我正在尝试从特定元素读取信息,这是我的xml有效负载:
<?xml version="1.0"?>
<tns:createTicket xmlns:tns="">
<contact>
<gender>F</gender>
<firstname>ANNE</firstname>
<lastname>MP</lastname>
<phone>88</phone>
</contact>
<issue>
<occurrenceDate>2020-03-23T00:01:00+01:00</occurrenceDate>
<location>
<streetName1>Rpp</streetName1>
<zipCode>999999</zipCode>
<city>AMMM</city>
<countryCode>FR</countryCode>
</location>
<typeCode>GAM</typeCode>
<otherInformations>
<name>Ser</name>
<value>Two</value>
</otherInformations>
<otherInformations>
<name>deliveryAddress</name>
<value>RURU</value>
</otherInformations>
**<otherInformations>
<name>**serDat**</name>
<value>**2020-03-23**</value>
</otherInformations>**
<otherInformations>
<name>gracias</name>
<value>False</value>
</otherInformations>
</issue>
</tns:createTicket>
如何从有效负载中读取该特定元素的信息:
串口 2020-03-23
我在代码中使用了Dom库,但是我只能从第一个“ otherinformations”元素中读取信息,而不能从其他元素中读取。当我想从XML有效负载中的唯一元素读取信息时,我没有这个问题。 编辑:我已经尝试过xPath librairy
var factory = DocumentBuilderFactory.newInstance()
var builder = factory.newDocumentBuilder()
var document = builder.parse(new Inputsource(new StringReader(payload)));
//var rootElement = document.getDocumentElement()
var xpf = XPathFactory.newInstance()
var xpath = xpf.newXPath()
print(payload)
var nodes = xpath.evaluate("/createTicketRequest/payload/issue/otherInformations",document,XPathConstants.NODESET) as NodeList
for(i in 0..nodes.getLength()) {
print(nodes.item(i).getNodeValue());
}
但是print(nodes.item(i).getNodeValue())的结果;是NULL
谢谢您的帮助!