Why can't I get the content of my XML?

Hi all. Here is a simple question. I have a XML document like:
<!DOCTYPE WEATHER SYSTEM "vpn2.dtd">
<TOTAL>
<VERSION_OUTIL>
1.1
</VERSION_OUTIL>
<VERSION>
2.23
</VERSION>
</TOTAL>
and I want to read 1.1 . I am sura that it is simple but not for me !!! Here is the code I test. I read the tag name but not the content could someone help me ?
public TestDOM (String xmlFile) {
// Create a Xerces DOM Parser
DOMParser parser = new DOMParser();
// Parse the Document
// and traverse the DOM
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
NodeList liste=document.getElementsByTagName("VERSION");
for (int i=0;i<1;i++){
     Node temp= liste.item(i);
     System.out.println (i+"*********"+document.getNodeValue());
System.out.println (i+"*********"+temp.getNodeValue()
}

What constitutes a node is kind of misleading:
the NodeList you have got contains one ELEMENT_NODE and what you want to print out is the TEXT_NODE which in fact is a child of the ELEMENT_NODE
If you try temp.getFirstChild().getNodeValue() it should work.
Using getFirstChild() is kind of cheating in that I know the TEXT_ELEMENT will be the first child. Not sure if there is a more general/elegant solution.

Similar Messages

Maybe you are looking for