我有一个XML字符串是这样的:如何使用javascript获取嵌入在xml标签中的值?
<?xml version="1.0"?>
<itemsPrice>
<setA>
<Category Code="A1">
<price>30</price>
</Category>
<Category Code="A2">
<price>20</price>
</Category>
</setA>
<setB>
<Category Code="A3">
<price>70</price>
</Category>
<Category Code="A4">
<price>80</price>
</Category>
</setB>
</itemsPrice>
如何获得属性“代码”的值在JavaScript变量或数组?我想要的是:A1,A2,A3,A4最好在一个数组中。或者,如果它可以在“每个”功能中获得,那也是很好的。我如何在JavaScript中为此做些什么?
这里是我的尝试:
var xml=dataString; // above xml string
xmlDoc = $.parseXML(xml);
$xml = $(xmlDoc);
$code = $xml.find("Category");
alert($code.text()); // gives me the values 30 20 70 80
// I want to get the values A1 A2 A3 A4
非常感谢。它工作完美! – zolio
@zolio而不是我的回答? –