posted 14 years ago
Hi,
Please help me in parsing the following XML snippet.
<Project>
<LevLanguages>
<lang>DEU</lang>
<lang>ESN</lang>
<lang>FRA</lang>
<lang>ITA</lang>
</LevLanguages>
</Project>
I want to get the values of the <lang> nodes.
I have tried with the following code and it give 'null' value.
Element docEl = doc.getDocumentElement();
NodeList nol = docEl.getElementsByTagName("LevLanguages");
Element levLang =(Element) nol.item(0);
NodeList lang = levLang.getElementsByTagName("lang");
System.out.println(lang.getLength());
if (lang != null && lang.getLength() > 0) {
for (int i = 0; i < lang.getLength(); i++) {
System.out.println("Language:"+((Element)lang.item(i)).getNodeValue());
}
}
Could someone please tell me what is wrong in this piece of code?
Thanks in Advance,
Raj S Kumar