wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes XML parsing large complex xml data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML parsing large complex xml data" Watch "XML parsing large complex xml data" New topic
Author

XML parsing large complex xml data

saish berger
Greenhorn

Joined: Apr 12, 2010
Posts: 3
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
Ranch Hand

Joined: Apr 04, 2009
Posts: 513
    
    6
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

Joined: Mar 22, 2000
Posts: 12805
    
    5
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

Joined: Apr 12, 2010
Posts: 3
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

Joined: Mar 22, 2000
Posts: 12805
    
    5
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

Joined: Apr 12, 2010
Posts: 3


I have started using sax and have printed all elements. Now working on mapping file to match the element.
Thanks for the start
Manoj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML parsing large complex xml data