2014-09-23 172 views
-1

我有以下XML文檔:遍歷XML結構

<order> 
     <book ISBN="0942407296"> 
      <title>Baking Extravagant Pastries with Kumquats</title> 
      <author> 
       <lastName>Contino</lastName> 
       <firstName>Chuck</firstName> 
      </author> 
      <pageCount>238</pageCount> 
     </book> 
     <book ISBN="0865436401"> 
      <title>Emu Care and Breeding</title> 
      <editor> 
       <lastName>Case</lastName> 
       <firstName>Justin</firstName> 
      </editor> 
      <pageCount>115</pageCount> 
     </book> 
    </order> 

拿到冠軍例如,我用:

myXML.book[0].title[0] 

我怎樣才能獲得國際標準書號(以下簡稱 「0942407296」)使用myXML.book...

+1

你可能想表示,因爲表達你給什麼語言你工作。我猜的Javascript,看上去像典型的Javascript醜陋... – keshlam 2014-09-23 02:03:36

+0

沒錯,這就是的JavaScript。 – user3566591 2014-09-23 15:30:36

+1

什麼是myXML? – 2014-09-23 23:51:47

回答

0
var final_r= new java.util.ArrayList(); 
stringBuilder = new java.lang.StringBuilder(); 
var xml_ISBN= new XML(stringBuilder); 
var final_rez = new Array(); 
//open the XML for reading 
var file = new java.io.FileReader (XML_location)); 
while ((line=file.readLine()) !=null) { 
//how many ISBN we have in the XML 
if (line.contains ("ISBN")) counter=counter+1; } 
} 
for (var i=0;i<counter;i++) { 
final_rez[i]=xml_ISBN.book[i]; var convert_str=(xml_ESI.book[i]).toString(); 
} 
0
// get XML 
var xml = xhr.responseXML; 

// get tag 
var tags = xml.getElementsByTagName("tagnamehere"); 
for (var i = 0; i < users.length; i++) { 
var tag = tags[i].firstChild.nodeValue; 
var tr = document.createElement("tr"); 
var td = document.createElement("td"); 
var textNode = document.createTextNode(tag); 
td.appendChild(textNode);   
tr.appendChild(td);   
document.getElementById("tbody").appendChild(tr); 
} 
+0

這也適用,謝謝 – user3566591 2014-09-26 00:40:37

+0

沒問題!很高興有幫助! – Petro 2014-09-26 16:53:55