如何在解析SOAP正文时从NodeList对象中提取属性值



所以我有一个xml soap消息,看起来像这样:

...
<FinalValueFee1 currencyID="USD">8.0</FinalValueFee>
<FinalValueFee2 currencyID="ILS">6.0</FinalValueFee>
<FinalValueFee3 currencyID="EUR">1.0</FinalValueFee>
<FinalValueFee4 currencyID="USD">4.0</FinalValueFee>
...

在设置了SOAPMessageSOAPBody的对象之后,我能够通过以下方式获取每个元素的值:

SOAPBody m_soapBody.getElementsByTagName("FinalValueFee1").item(0).getTextContent();

我应该如何为它们中的每一个选择currencyID

m_soapBody.getElementsByTagName("FinalValueFee1").item(0)返回一个Node对象。在这样的对象下可用的各种方法可以在这里查看:

http://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Node.html

通过查看文档,以下任何一项都应该得到您想要的值:

    node.getAttributes().getNamedItem("currencyID").getNodeValue();
    node.getAttributes().getNamedItem("currencyID").getTextContent();

最新更新