Search code examples
javascriptxmlrhino

Traverse XML Structure


I have the following XML doc:

<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>

To get the title for example, I use:

myXML.book[0].title[0]

How can I get the ISBN (the "0942407296") using the myXML.book...?


Solution

  • 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(); 
    }