parentNodeの子ノードにアクセスする際に問題があります。以下は、私が働いているXMLです:親ノードの子ノードにアクセスする方法
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource src = new InputSource();`
src.setCharacterStream(new StringReader(response));
Document doc = builder.parse(src);
String amount =doc.getElementsByTagName("amount").item(0).getTextContent();
NodeList nodeList = doc.getElementsByTagName("tax");
for (int i = 0; i < nodeList.getLength(); i++)
{
Node childNode = nodeList.item(i);
}
どのように私は要素税の内側DESCRIPT、taxAmtとtaxCodeを取得するようにしてください:以下
String response = "<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<closure>
<amount>1055296.0000</amount>
<currency>USD</currency>
<unit>2</unit>
<year>2012</year>
<taxes>
<tax>
<descript>FEE LEVY</descript>
<taxAmt>
<amt>30304.0000</amt>
<currency>USD</currency>
</taxAmt>
<taxCode>SUR</taxCode>
</tax>
<tax>
<descript>MED LEVY</descript>
<taxAmt>
<amt>25125.0000</amt>
<currency>USD</currency>
</taxAmt>
<taxCode>CIS</taxCode>
</tax>
</taxes>
</closure>";
は私がしようとしているコードはありますか?
XMLをインデントしてください。 – Kaushal28
@ Kaushal28 ...私は自分のXMLをうまくインデントしました。 – hyzic23