2014-01-08 108 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

相關問題