我希望从下面的 SOAP/XML 字符串中提取 ItemName 和 Value 对。我已经通过网络尝试了各种正确的方法来做到这一点。我已经放弃了,只想将数据解析为字符串。我已经查看了 XSLT,但我需要将 SOAP 数据与一些人类可读的数据相关联,因此将它们全部放在 JavaScript 数组中对我来说会更好。
[删除了我可怕的原始 JavaScript 代码块并用好的代码替换。]
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ReadResponse xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/">
<ReadResult RcvTime="2012-05-02T13:25:39.484+01:00" ReplyTime="2012-05-02T13:25:39.484+01:00" RevisedLocaleID="en" ServerState="running"> </ReadResult>
<RItemList>
<Items ItemName="_System._DateTime">
<Value xsi:type="xsd:dateTime">2012-05-02T12:25:38.000+01:00</Value>
<Quality></Quality>
</Items>
<Items ItemName="_System._ProjectTitle">
<Value xsi:type="xsd:string">Job2663</Value>
<Quality></Quality>
</Items>
</RItemList>
</ReadResponse>
</soap:Body>
</soap:Envelope>
//Edited below to include correct code based on Rocket's solution below.
$(soap).find('Items').each(function(){
console.log($(this).attr('ItemName'), ':', $('Value', this).html());
});
非常感谢。