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.
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.
Joined: Apr 12, 2010
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.
Author and all-around good cowpoke
Joined: Mar 22, 2000
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.
Joined: Apr 12, 2010
I have started using sax and have printed all elements. Now working on mapping file to match the element.
Thanks for the start