2014-01-08 112 views
0

你好,提前谢谢你,返回具有特定属性名称的XML节点

我的问题是关于AJAX返回/解析XML信息。

我返回了一个成功的请求,但是我返回了所有的XML节点ngPropertyName。我想要完成的是返回所有ngPropertyName xml节点,仅用于特定类别(物理,媒体,家庭等)。

$(xml).find('ngCategory').each(function(){ 
      $(xml).find('ngPropertyName').each(function(){ 
       var profilePhysicalAt = $(this).text(); 
       result += "<li>" + profilePhysicalAt + "</li>"; 
      }) 
    }); 

    <ngCategory name="PHYSICAL"> 
    <ngProperty> 
     <ngPropertyID>1287</ngPropertyID> 
     <ngPropertyName>Height</ngPropertyName> 
     <ListItems> 
     <Item id="725">3'0</Item> 
     <Item id="726">3'1</Item> 
     </ListItems> 
    </ngProperty> 
<ngProperty> 
    <ngPropertyID>1288</ngPropertyID> 
    <ngPropertyName>Weight</ngPropertyName> 
    <ListItems> 
    <Item id="797">25</Item> 
    <Item id="798">26</Item> 
    <Item id="799">27</Item> 
     </ListItems> 
    </ngProperty> 

    </ngCategory> 

    <ngCategory name="Medical"> 
    <ngProperty> 
     <ngPropertyID>1287</ngPropertyID> 
     <ngPropertyName>Height</ngPropertyName> 
     <ListItems> 
     <Item id="725">3'0</Item> 
     <Item id="726">3'1</Item> 
     </ListItems> 
    </ngProperty> 

总体来说,我想返回所有ngPropertyName针对特定的类别。目前,我正在从我所有的cateogries中提取所有的ngPropertyName。

谢谢。

回答

0

为此,您需要使用xml DOM。

请点击此链接: http://www.w3schools.com/dom/dom_nodes_get.asp

请不要尝试使用jQuery的API来解压。

+0

试过这个。 Did not work alert(“Get Physical Nodes”); \t如果(window.XMLHttpRequest) \t { \t \t xhttp =新的XMLHttpRequest(); \t} \t别的// IE 5/6 \t { \t \t xhttp =新的ActiveXObject( “Microsoft.XMLHTTP”); \t} \t xhttp.open(“GET”,“URL”,false); \t xhttp.send(); \t xmlDoc = xhttp.responseXML; \t \t var a = xmlDoc.getElementsByTagName(“ngdataset”); \t var b = a.getElementsByTagName(“ngCategory”)[0]; \t var c = b.getElementsByTagName(“ngProperty”)[0]; \t var x = c.getElementsByTagName(“ngPropertyID”)[0]; \t var y = x.childNodes [0]; \t var txt = y.nodeValue; \t \t alert(txt); – user2626307

相关问题