I have a doubt in parsing. I am trying to parse a file "Address.xml" it runs successfully, it prints tag and value but if i pass sample.xml it doesn't print tag value of ISBN
--Address.xml-------- it works----------------------
<?xml version="1.0" encoding="UTF-8"?>
<addr:address type="Billing"
xmlns:addr="http://www.Monson-Haefel.com">
<!-- The address follows standard U.S. postal format -->
<name>AMAZON.COM</name>
<street>1850 Mercer Drive</street>
<city>Macon</city>
<state>KY</state>
<zip>40511</zip>
</addr:address>
-------sample.xml------------dosn't work
<?xml version="1.0" encoding="UTF-8"?>
<
soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:mh="http://www.Monson-Haefel.com/jwsbook/BookQuote">
<soap:Body>
<getBookPrice>
<isbn>0321146182</isbn>
</getBookPrice>
</soap:Body>
</soap:Envelope>
---------------------
java code----------- i am missing another loop to go isbn tag but i tried that also not working-----------
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {
docBuilder = factory.newDocumentBuilder();
try {
Document doc=docBuilder.parse("sample.xml");
Element rootElement=doc.getDocumentElement();
// Output the elements contained by the root element.
NodeList nodeList = rootElement.getChildNodes();
for(int i=0;i < nodeList.getLength();i++){
Node node= nodeList.item(i);
if(node.getNodeType() == Node.ELEMENT_NODE){
String tagName = node.getNodeName();
System.out.println("tagname "+tagName);
NodeList nodeList2 = node.getChildNodes();
for(int j=0; j < nodeList2.getLength();j++){
Node text = (Node) nodeList2.item(j);
System.out.println("text "+text.getNodeValue());
}
}
}
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}