getting node value exception
<amount currency="USD">1000500</amount>
while parsing above string i am getting only attribute value .when i try to get node value null pointer exception
for getting node value using
NodeList amountList= estimateElement.getElementsByTagName("amount");
Element amtElement= (Element)amountList.item(0);
String amount=amtElement.getFirstChild().getnodevalue()
Th开发者_StackOverflow中文版anks in advance
Aswan
Please try this. I assume that it is true:
NodeList list = estimateElement.getElementsByTagName("amount").item(0).getChildNodes();
Node node = (Node) list.item(0);
String value = node.getNodeValue();
Source : DOM parser
Element amtElement= (Element)amountList.item(0);
seems to be your element - so why are you calling getFirstChild()?
try this:
String amount=amtElement.getnodevalue()
have you checked out jdom? it has a nice documentation and is easy to use..
Try using the getTextContent()
method:
NodeList amountList= estimateElement.getElementsByTagName("amount");
Element amtElement= (Element)amountList.item(0);
String amount=amtElement.getTextContent();
See here for more info.
精彩评论