如何从xml中检索node_names和attribute_names(不是节点或属性的值)是否可以使用jquery?
<Client>
<product name="astro">
<service_process name="ACID">
<host>pable</host>
<port>18848</port>
</servcice_process>
<service_process name="Mestro">
<host>Mico</host>
<port>18821</port>
</servcice_process>
</product>
</Client>
答案 0 :(得分:2)
您可以从this开始:
var xml = '<Client><product name="astro"><service_process name="ACID"><host>pable</host><port>18848</port></servcice_process><service_process name="Mestro"><host>Mico</host><port>18821</port></servcice_process></product></Client>';
$(xml).each(function displayChildren (i, node) {
console.log(node.nodeName);
// traverse attributes
$.each(node.attributes, function (j, attr) {
console.log(attr.nodeName, attr.nodeValue);
});
// recursive call
$(node).children().each(displayChildren);
});
答案 1 :(得分:0)