如何使用 Node.js 从 XML 字符串中获取值

2023-11-22

假设您有以下 xml:

<yyy:response xmlns:xxx='http://domain.com'> 
    <yyy:success> 
        <yyy:data>some-value</yyy:data> 
    </yyy:success> 
</yyy:response>

我如何检索之间的值<yyy:data>使用 Node.js?

Thanks.


节点 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']);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Node.js 从 XML 字符串中获取值 的相关文章

随机推荐