Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XML to be Split  RSS feed

 
Shan Narayanan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a XML that has to be sent to Webservice a request.

XML format :
<Head- Envelope>
<body>
<RequestItems>
<ID> 1 </ID>
<name>xxxxxx</name>
</RequestItems>
<requestItems>
<ID>2 </ID>
<name>aaaaaaaaa</name>
</RequestItems>
</body>
</head-envelope>

I will be having 10000 just requestItem's ID . But the Webservices can process only 1000 at a time. SO i have to split the XML dynamically and have to send to request in a block of 1000's with out changing their ID's.

Any Logic to split the xml checking the id? Thanks in advance!!!
 
Paul Clapham
Sheriff
Posts: 22473
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't approach that by generating the whole XML and then trying to split it into smaller XMLs. I would approach it by splitting the set of IDs to be processed into smaller subsets and then generating the XML for each of the subsets.
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shan,
Assuming you already considered Paul's advice, I would say to use XML parsing combined with SAAJ to make mulitple web service calls out of one big xml.
 
Christopher Nortje
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shan,
I agree with Paul, if you have a large amount of data it’s best to create multiple requests from the initial data. You could also look into XSTL.
Here is a simple un-optimised example:

Just replace the input streams and output streams.



RequestItemsOriginalRequest.xml


RequestItemsExtractor.xsl


This is the output result:


Extract from node [1 to 3] <?xml version="1.0" encoding="UTF-8"?>
<head-envelope><body><RequestItems><ID>1</ID><name>aaaa</name></RequestItems><RequestItems><ID>2</ID><name>bbbb</name></RequestItems><RequestItems><ID>3</ID><name>ccc</name></RequestItems></body></head-envelope>

Extract from node [4 to 6] <?xml version="1.0" encoding="UTF-8"?>
<head-envelope><body><RequestItems><ID>4</ID><name>ddd</name></RequestItems><RequestItems><ID>5</ID><name>eee</name></RequestItems><RequestItems><ID>6</ID><name>fff</name></RequestItems></body></head-envelope>

Extract from node [7 to 9] <?xml version="1.0" encoding="UTF-8"?>
<head-envelope><body><RequestItems><ID>7</ID><name>ggg</name></RequestItems><RequestItems><ID>8</ID><name>hhh</name></RequestItems></body></head-envelope>

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!