私はnode.js
を初めて利用しており、XML
を解析する必要があります。 jsでは、私はちょうどDOMParser
を使用し、私が望む値を得るためにgetElementsByTagName
を使用します。私はちょうどノードに切り替えて、xml2js
(代替案を検討する意思がある)を使用しています。私は、私が探しているものを得るための応答を解析する方法を理解することができませんでした。以下xml2jsで解析する
コード:私の関数の出力ここで
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere">
<soapenv:Header/>
<soapenv:Body>
<int:readResponse>
<response>
<request>?</request>
<cust>
<fName>?</fName>
</cust>
</response>
</int:readResponse>
</soapenv:Body>
</soapenv:Envelope>
されています:
{ 'soapenv:Envelope':
{ '$':
{ 'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
'xmlns:int': 'realURLHere' },
'soapenv:Body': [ [Object] ]
}
}
私はここに
function parseBody(body){
var parseString = require('xml2js').parseString;
var xml = body
parseString(xml, function (err, result) {
console.dir(result);
});
とは、私は関数に渡していたXMLです<cust>
にある<fName>
の値にアクセスしようとしましたが、運がありません。どんな助けもありがとう。ありがとう!
以下の回答を試してみてくださいを使用してアクセスすることができます
をプリントアウトし、この
をお試しください –