假设您有这个 xml:
<yyy:response xmlns:xxx='http://domain.com'>
<yyy:success>
<yyy:data>some-value</yyy:data>
</yyy:success>
</yyy:response>
我如何检索 <yyy:data>
之间的值?使用 Node.js?
谢谢。
最佳答案
node-xml2js图书馆会帮助你。
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var xml = '\
<yyy:response xmlns:xxx="http://domain.com">\
<yyy:success>\
<yyy:data>some-value</yyy:data>\
</yyy:success>\
</yyy:response>';
parser.parseString(xml, function (err, result) {
console.dir(result['yyy:success']['yyy:data']);
});
关于xml - 如何使用 Node.js 从 XML 字符串中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9611450/