Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery和XML是解析的最佳方式_Jquery_Xml_Parsing - Fatal编程技术网

jQuery和XML是解析的最佳方式

jQuery和XML是解析的最佳方式,jquery,xml,parsing,Jquery,Xml,Parsing,尝试从Web服务vinquery.com解析XML结果时,值通常位于关键字名称之间,例如hello,但返回的XML为: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <VINquery Version="1.0.0" Report_Type="BASIC" Date="1/19/2012"> <VIN Number="1ZVFT80N475337065" Status="SUCCESS">

尝试从Web服务vinquery.com解析XML结果时,值通常位于关键字名称之间,例如hello,但返回的XML为:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<VINquery Version="1.0.0" Report_Type="BASIC" Date="1/19/2012">
    <VIN Number="1ZVFT80N475337065" Status="SUCCESS">
        <Vehicle VINquery_Vehicle_ID="32627" Model_Year="2007" Make="Ford" Model="Mustang" Trim_Level="V6 Deluxe Coupe">
            <Item Key="VINquery_Vehicle_ID" Value="32627" Unit="" />
            <Item Key="Model Year" Value="2007" Unit="" />
            <Item Key="Make" Value="Ford" Unit="" />
            <Item Key="Model" Value="Mustang" Unit="" />
            <Item Key="Trim Level" Value="V6 Deluxe Coupe" Unit="" />
            <Item Key="Manufactured in" Value="UNITED STATES" Unit="" />
            <Item Key="Production Seq. Number" Value="337065" Unit="" />
            <Item Key="Body Style" Value="COUPE 2-DR" Unit="" />
            <Item Key="Engine Type" Value="4.0L V6 SOHC 12V" Unit="" />
            <Item Key="Transmission-short" Value="5A | 5M" Unit="" />
            <Item Key="Transmission-long" Value="5-Speed Automatic | 5-Speed Manual" Unit="" />
            <Item Key="Driveline" Value="RWD" Unit="" />
            <Item Key="Tank" Value="16.00" Unit="gallon" />
            <Item Key="Fuel Economy-city" Value="18 - 19" Unit="miles/gallon" />
            <Item Key="Fuel Economy-highway" Value="26 - 28" Unit="miles/gallon" />
            <Item Key="Anti-Brake System" Value="Non-ABS | 4-Wheel ABS" Unit="" />
            <Item Key="Steering Type" Value="R&amp;P" Unit="" />
            <Item Key="Standard Seating" Value="4" Unit="" />
            <Item Key="Optional Seating" Value="No data" Unit="" />
            <Item Key="Length" Value="187.60" Unit="in." />
            <Item Key="Width" Value="74.00" Unit="in." />
            <Item Key="Height" Value="54.50" Unit="in." />
        </Vehicle>
</VIN>
</VINquery>

使用
$(xml)
或其他方法获取say
Item Key=“Body Style”
值的最有效方法是什么

谢谢

jQuery.parseXML():


使用属性过滤器,特别是attributeEquals过滤器:

$("node[Key='Bob Style']"); 

varx='1〕\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
';
警报($(x).find(“项[Key='Body Style'])).attr('Value');

您的意思是您尝试了jQuery的自动bultin XML解析,但遇到了性能问题吗?
$("node[Key='Bob Style']"); 
var x='<VINquery Version="1.0.0" Report_Type="BASIC" Date="1/19/2012">\
    <VIN Number="1ZVFT80N475337065" Status="SUCCESS">\
        <Vehicle VINquery_Vehicle_ID="32627" Model_Year="2007" Make="Ford" Model="Mustang" Trim_Level="V6 Deluxe Coupe">\
            <Item Key="VINquery_Vehicle_ID" Value="32627" Unit="" />\
            <Item Key="Model Year" Value="2007" Unit="" />\
            <Item Key="Make" Value="Ford" Unit="" />\
            <Item Key="Model" Value="Mustang" Unit="" />\
            <Item Key="Trim Level" Value="V6 Deluxe Coupe" Unit="" />\
            <Item Key="Manufactured in" Value="UNITED STATES" Unit="" />\
            <Item Key="Production Seq. Number" Value="337065" Unit="" />\
            <Item Key="Body Style" Value="COUPE 2-DR" Unit="" />\
            <Item Key="Engine Type" Value="4.0L V6 SOHC 12V" Unit="" />\
            <Item Key="Transmission-short" Value="5A | 5M" Unit="" />\
            <Item Key="Transmission-long" Value="5-Speed Automatic | 5-Speed Manual" Unit="" />\
            <Item Key="Driveline" Value="RWD" Unit="" />\
            <Item Key="Tank" Value="16.00" Unit="gallon" />\
            <Item Key="Fuel Economy-city" Value="18 - 19" Unit="miles/gallon" />\
            <Item Key="Fuel Economy-highway" Value="26 - 28" Unit="miles/gallon" />\
            <Item Key="Anti-Brake System" Value="Non-ABS | 4-Wheel ABS" Unit="" />\
            <Item Key="Steering Type" Value="R&amp;P" Unit="" />\
            <Item Key="Standard Seating" Value="4" Unit="" />\
            <Item Key="Optional Seating" Value="No data" Unit="" />\
            <Item Key="Length" Value="187.60" Unit="in." />\
            <Item Key="Width" Value="74.00" Unit="in." />\
            <Item Key="Height" Value="54.50" Unit="in." />\
        </Vehicle>\
</VIN>\
</VINquery>';

alert($(x).find("Item[Key='Body Style']").attr('Value'));