在 Node.js 中解析 XML 字符串的最简单方法是什么?
问题描述:
我环顾四周,没有看到在 Node.js 中解析 XML 的明显方法.我假设有一些相对直接的 XML 对象,我可以将字符串或 url 传递给它,但我在规范中没有找到类似的东西.我需要外部库吗?如果是这样,你们会推荐哪一个?我不需要 xPath(虽然我不介意),只要我能以一种明显的方式遍历树(测试 nodeType == ElementNode 并循环遍历孩子).
I'm looking around and not seeing an obvious way to parse XML in Node. I'm assuming that there's some relatively straight forward XML object that I can pass a String or url to, but I'm not finding anything like that in the spec. Do I need an external lib? and if so, which one would you guys recommend? I don't need xPath (though I wouldn't mind it) as long as I can walk the tree in an obvious way (test if nodeType == ElementNode and loop through children).