How to loop through many XML messages and parse them ?
Hi All
I have been trying very hard to loop through many XML messages and process each of them. Let me first explain the problem -
Suppose I have the following String -
<xyz>
....
<abc>happy</abc>
....
</xyz>
<xyz>
....
<abc>new</abc>
....
<xyz>
<xyz>
....
<abc>year</abc>
....
</xyz>
I have to process each message within the <xyz></xyz> tag and find the falue of <abc> element (happy, new and year).
The extraction of <abc> value is very simple, I am using SAX parser's startElement() method to check every element's name and if the element's name is <abc> pick up the value. But I am not able to loop through the different messages within the <xyz></xyz> tag.
I am thinking of using another DOM parser -
DOMParser domParser = new DOMParser();
StringReader rdr = new StringReader(inputXML);
InputSource src = new InputSource(rdr);
domParser.parse(src);
Document doc = domParser.getDocument();
NodeList nodeList = doc.getElementsByTagName("xyz");
Now I can loop through this nodeList, but not able to. Is using the DOM parser and NodeList the preferable way of lopping through the messages, then how I can loop through ? Or is there any other way ?
I have been trying on this for quite a few days, but not able to. Can you please help me out ?
Thanking you in advance ....
Nirmalya Sinha

