如何用jQuery读取这个XML文件?
对于“普通标签”,没有问题,例如:< car> Mustang< / car>
对于“普通标签”,没有问题,例如:< car> Mustang< / car>
HTML / jQuery的:
$(document).ready(function(){ $.get("AMA.xml",function(XMLArray){ $(XMLArray).find("dataset").each(function(){ var $myAMA = $(this); var number = $myAMA.attr("article.plunumber"); var name = $myAMA.attr("article.name"); var price = $myAMA.attr("article.price").text(); $("#AMAContainer").append("<p>"+number+"<br>"+name+"<br>"+price+"</p>"); }); }); });
XML文件:
<document name="screen"> <section name="list"> <dataset> <var key="type">article</var> <var key="article.number">1</var> <var key="article.name">Testname1</var> <var key="article.displayname"/> <var key="article.price">99,99</var> <var key="article.plunumber">1</var> <action key="STANDARD">bp1;</action> </dataset> <dataset> <var key="type">article</var> <var key="article.number">2</var> <var key="article.name">Testname2</var> <var key="article.price">88,88</var> <var key="article.plunumber">2</var> <action key="STANDARD">bp2;</action> </dataset> </section> </document>
我绝对不知道如何读取这些值.
我只需要三个(数字,名称,价格).
您可以按属性选择元素,只需使用属性选择器或filter()函数等.
$(document).ready(function () { $.get("AMA.xml",function (XMLArray) { var xml = $.parseXML(XMLArray); $(xml).find("dataset").each(function () { var number = $('[key="article.plunumber"]',this).text(); var name = $('[key="article.name"]',this).text(); var price = $('[key="article.price"]',this).text(); $("#AMAContainer").append("<p>" + number + "<br>" + name + "<br>" + price + "</p>"); }); }); });