• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parsing large complex xml data

 
saish berger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a requirement were our J2EE application will receive large complex xml data from third party. We need to read thru the whole xml elements. Any xml elements matching our list of screen fields will have to be retrieved. The screen field name is not same as xml element name.
One of the approach is to have a predefined list which will have the actual xml element and corresponding screen field name listed. This mapping list can be a mapping xml or a java hashmap set. While reading thru the xml data if any xml element is matching with the elment on the mapping file, then we need to write to a hashmap the screen field name as key taken from the maping file and the value will be the value from the matched xml element. After reading the complete xml , all matched entries will need to be added to hashmap.
Is there a way to implement this in java considering that we need to parse/read a very complex xml data , memory and response time parsing thru the xml.

Thanks in advance.
Saish.
 
Karthik Shiraly
Bartender
Posts: 1207
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do you want to know which would be the optimum solution to process the 3rd party XML, or do you want to know which data structures to use to transfer xml fields to screen?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that your "large xml data' really is to large to treat as a DOM, this means you will be using SAX or STax style parsing. This will be surprisingly fast but take considerable programming. If you need examples, search for "Harold Processing XML with Java" to get a link to his free online book.

Bill
 
saish berger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Karthik
Thanks for the reply. I have not worked on processing XML, iam reading lot of articles of using jaxb, castor,jibx and about binding to java objects. I can go with the baisc approach of reading thru the xml using Sax and check each element and do the processing as i require. Not sure if this is the way to go.

what i need to know what is the best approach to read the 3rd party xml file and on reading how we can match each xml element with entries in hashmap list. The hashmap list consists of screen field name and value which is the XML element name. The hashmap list , call it a mapping file can be loaded from a configuration/properties file.

If a match is found then i need to write this data to another hashmap list. The new list written will be screen fields and coresponding values taken from the XML.

The objective is to map the data from the 3rd party to mulitple screen fields. The screen fields name is not same as the xml element name.

Thanks
Saish
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you would find those various toolkits such as JAXB, castor, etc to be a real pain to implement because you have no control over the format of this file you have to read. So it looks like SAX or STax for you.

Approach the problem gradually and experiment.
First get the parser running and locating/printing element names
Learn how the API lets you get at the Element and attribute contents - see org.w3c.dom.Node documentation.
Pay particular attention to the characters() method, it is NOT guaranteed to get the entire contents of a Text node in one call.
Worry about your mapping problem after you are comfortable with parsing.

Bill

 
saish berger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have started using sax and have printed all elements. Now working on mapping file to match the element.
Thanks for the start
Manoj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic