I am facing a issue with DOm parsing. I have the XML:
<?xml version="1.0"?>
<item>
<stock-field>
<name>pin-number</name>
<value>12345678901234</value>
<display>true</display>
</stock-field>
<stock-field>
<name>toll-free-number</name>
<value>1800121212121</value>
<display>true</display>
</stock-field>
</item>
I need to create a hashmap of all possible stock-field names and values. The displcay tag is not of much relevance.
I am using now the following code:
Element root = doc.getDocumentElement();
NodeList stocklist = root.getElementsByTagName("stock-field");
String text = "";
Node stockfield, fieldnode = null;
NodeList nodes = null;
for (int i=0; i< stocklist.getLength(); i++ ) {
stockfield = stocklist.item(i);
nodes = stockfield.getChildNodes();
for (int j=0; j < nodes.getLength(); j++ ) {
fieldnode = nodes.item(j);
text = fieldnode.getNodeValue();
System.out.println ("\n Name: "+fieldnode.getLocalName()+" Type: "+fieldnode.getNodeType());
if (fieldnode.getNodeType() == Node.TEXT_NODE){
System.out.println("Value: "+text);
}
}
}
But the value (text String var) is always null as in doesnot carry the value of the element..
The output for the System.out is always Value: 'blank'
what am i doing wrong?
[ March 10, 2003: Message edited by: Manu Anand ]