【发布时间】:2017-12-05 04:59:29
【问题描述】:
在解析从 NodeJS 中 SOAP Web 服务的 XML 响应创建的 JSON 时,我需要帮助。我想要一个 notifications 的 JSON 数组。
XML如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getNotificationsResponse xmlns:ns2="---url---">
<return>
<notifications>
<ackRequired>false</ackRequired>
<body>Testing Notitfications</body>
<created>1498798404874</created>
<gpsAlt>1.0</gpsAlt>
<gpsLat>1.0</gpsLat>
<gpsLong>1.0</gpsLong>
<messageId>253</messageId>
<priority>INFORMATIONAL</priority>
<senderClientId>PMC0</senderClientId>
<status>SENT</status>
<subject>Test Notification</subject>
<updated>1498798404874</updated>
<userId>1</userId>
<userLogin>ipics</userLogin>
</notifications>
<notifications>
<ackRequired>false</ackRequired>
<body>Test notitfication</body>
<created>1498797535714</created>
<gpsAlt>0.0</gpsAlt>
<gpsLat>0.0</gpsLat>
<gpsLong>0.0</gpsLong>
<messageId>244</messageId>
<priority>HIGH</priority>
<senderClientId>PMC_1234</senderClientId>
<status>SENT</status>
<subject>Test</subject>
<updated>1498797535714</updated>
<userId>1</userId>
<userLogin>ipics</userLogin>
</notifications>
<notifications>
<ackRequired>false</ackRequired>
<body>Testing Notitfications</body>
<created>1498794764538</created>
<gpsAlt>1.0</gpsAlt>
<gpsLat>1.0</gpsLat>
<gpsLong>1.0</gpsLong>
<messageId>239</messageId>
<priority>INFORMATIONAL</priority>
<senderClientId>PMC0</senderClientId>
<status>SENT</status>
<subject>Test Notification</subject>
<updated>1498794764538</updated>
<userId>1</userId>
<userLogin>ipics</userLogin>
</notifications>
<notifications>
<ackRequired>false</ackRequired>
<body>Testing Notitfications</body>
<created>1498794760123</created>
<gpsAlt>1.0</gpsAlt>
<gpsLat>1.0</gpsLat>
<gpsLong>1.0</gpsLong>
<messageId>234</messageId>
<priority>INFORMATIONAL</priority>
<senderClientId>PMC0</senderClientId>
<status>SENT</status>
<subject>Test Notification</subject>
<updated>1498794760123</updated>
<userId>1</userId>
<userLogin>ipics</userLogin>
</notifications>
</return>
</ns2:getNotificationsResponse>
</soap:Body>
</soap:Envelope>
我正在使用 xmldom 节点模块。
我的代码如下,但没有给出正确的响应。
var doc = new DOMParser().parseFromString(data.response, 'text/xml');
var valueXML = doc.getElementsByTagName('return');
var temp = valueXML[0].getElementsByTagName("notifications")[0];
var output = temp.getElementsByTagName("nextSibling")._node.childNodes.parentNode
【问题讨论】:
-
valueXML[0].children怎么样 -
@ShanilFernando,它返回未定义