• Share
  • ?
  • Profiles ▼
  • Communities ▼
  • Apps ▼

Blogs

  • My Blogs
  • Public Blogs
  • My Updates

This community can have members from outside your organization. HermannSW

  • Log in to participate

▼ Tags

▼ Similar Entries

Howto: easy callout ...

Blog: HermannSW
HermannSW 2700006U54
Updated
0 people like thisLikes 0
No CommentsComments 0

Spring MVC Controlle...

Blog: Dougclectica
DougBreaux 270007SMYJ
Updated
0 people like thisLikes 0
No CommentsComments 0

JAXB @XmlRootElement...

Blog: Dougclectica
DougBreaux 270007SMYJ
Updated
0 people like thisLikes 0
No CommentsComments 0

DataPower as a REST ...

Blog: Me, myself an...
Offline 0600018ME9
Updated
1 people likes thisLikes 1
No CommentsComments 0

All Application Lang...

Blog: DB2 Performan...
DaveBeulke 2700023WUN
Updated
0 people like thisLikes 0
No CommentsComments 0

▼ Similar Ideas

Built in Transform &...

Ideation Blog: IBM PureData-...
santosh_hegde 060002755N
Updated
Votes 2 CommentsComments 1

▼ Archive

  • March 2018
  • November 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • October 2016
  • May 2016
  • April 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011

▼ Blog Authors

HermannSW

View All Entries
Clicking the button causes a full page refresh. The user could go to the "Entry list" region to view the new content.) Entry list

XML to JSON Transformation

HermannSW 2700006U54 | | Tags:  xslt json xml datapower jsonx transform ‎ | 2 Comments ‎ | 20,425 Views

In developerWorks DataPower forum thread Need Help With XML to Json Transformation the question was raised on how to transform XML to JSON.

I did propose a transformation from XML to JSONX and then making use of "store:///jsonx2json.xsl" transformation to get the JSON output:
https://www.ibm.com/developerworks/community/forums/html/topic?id=16b84014-8bea-401f-91cd-a8339bbccca8#19661af3-7666-4c05-b6a1-d9705c826617

Pros of that approach:

  • genereric where possible (xsl:templates with mode "number" and "string")
  • specific where needed (where are arrays, where are objects? arguments, see this posting)
  • gets all difficulties resolved for free (JSON string escaping rules, performance of these escapings)
  • just need to focus on transform XML->JSONX, no need to think about JSON


Now I wanted to know "the price" of that approach.
First I created bigger input by "./rdp87 1000 >rdp87.1000.xml" with this script:

$ cat rdp87
#!/bin/bash
echo "<response>"
echo "   <ver>2.0</ver>"
echo "   <source>31</source>"
for((i=1; i<=$1; ++i))
do
let t=$i+23
let b=$i+40000
echo "   <data>"
echo "      <table>"$t"</table>"
echo "      <batch>"$b"</batch>"
echo "   </data>"
done
echo "</response>"
$


From my initial XML-->JSONX-->JSON transformation rdp87.2.xsl:

 

I created "all-in-one" stylesheet for doing the XML-->JSON transformation rdp87.3.xsl:

 

Now I created two XML FW on a box with 4.0.2.13 firmware containing the (performance) fix for APAR IC90781 from May 2013 fixpack.
Both services used an XML Manager with "Profile Rule" in XML Manager's Compile Options policy.

Finally I did:

  • clear stylesheet cache for XML manager "profile"
  • send 1000 requests to service by
    $ time for((f=1;f<=1000;++f)); do curl --data-binary @rdp87.1000.xml http://dp7-l3:port ; echo; done
  • switch to "Status->XML Processing->Stylesheet Profiles" in WebGUI and take screenshot

 

Here is Stylesheet Profiles for XML->JSONX->JSON:
image

 

 

 

 

 

 

 

And here is Stylesheet Profiles for XML->JSON:
image

 


 

 

Yes, the total time taken for rdp87.2.xsl (1961ms) in the templates is by a factor of 2.66 greater than that of rdp87.3.xsl (735ms).

But that does only make an effect if the whole operation of a service is just XML->JSON conversion.
Typically in real live services other operations like AAA, SLM actions or other will happen.

If this is the case, then the (small) runtime overhead added is outweighted by maintainability and ease of stylesheet in my eyes.
 

<UPDATE>
rdp87.2a.xsl runtime is reduced by 15% compared to rdp87.2.xsl in making use of <xsl:import> and <xsl:apply-templates> instead of dp:transform().

This is the really small diff:

$ diff rdp87.2.xsl rdp87.2a.xsl
6a7,8
>   <xsl:import href="store:///jsonx2json.xsl"/>
>
24c26
<     <xsl:copy-of select="dp:transform('store:///jsonx2json.xsl', $jsonx)"/>
---
>     <xsl:apply-templates select="$jsonx/*" />
$

</UPDATE>
 

Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

 

Modified on by HermannSW 2700006U54
  • Add a Comment Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry
Notify Other People
notification

Send Email Notification

+

Quarantine this entry

deleteEntry
duplicateEntry

Mark as Duplicate

  • Previous Entry
  • Main
  • Next Entry
Feed for Blog Entries | Feed for Blog Comments | Feed for Comments for this Entry