Parsing complex XML data structure

Results 1 to 2 of 2

Thread: Parsing complex XML data structure

  1. #1
    Barb Guest

    Default Parsing complex XML data structure

    I am trying to access the data in a complex XML structure. I didn&#039;t write the XML. The structure is many levels deep with nested levels. For example, there&#039;s an element called "airitem" that can occur 0 - many times, and for each "airitem", there is an "airline" element that can only occur once. "airline" has an attribute called "airlinecode". I know how to use selectNodes to get to the "airitem" element and it&#039;s attributes, but I cannot figure out what method to use to access the elements buried down in that element. I want to loop through each "airitem" and get the data I need out of all of its descendants.<BR>(Oh, I need this to work with IE4 too...I don&#039;t have the luxury of only being compatible with IE5+).<BR><BR>Here&#039;s an example of my code:<BR><BR>objXMLDocument = new ActiveXObject("microsoft.xmldom");<BR>objXMLDocume nt.async = false;<BR>BusinessObjectURL = "";<BR>HttpReq = Server.CreateObject("Rope.WireTransfer");<BR>HttpR eq.SetHeader( "Content-Type", "text/xml" );<BR>HttpReq.SetHeader( "Content-Length", "" + sRequestXML.length );<BR>sXMLResponse = HttpReq.PostDataToURI( BusinessObjectURL, sRequestXML); <BR>objXMLDocument.loadXML("" + sXMLResponse); <BR><BR>objAirItem = objXMLDocument.selectNodes("serializedstream/displayreservationresponse/itinerarydata/airdata/airitem"); //this line works<BR><BR>var arrAirSegment = new Array();<BR>for (i = 0; i &#060; objAirItem.length; i++) { //air segment<BR> objNode = objAirItem.nextNode();<BR> objAttributes = objNode.attributes;<BR><BR> //the next line works because "flightnumber" is an attribute of "airitem".<BR> arrAirSegment[i] = arrAirSegment[i] + <BR> objAttributes.getNamedItem("flightnumber").nodeVal ue + "~";<BR><BR> //now I want to get an element further down in the tree.<BR> objAirAirline = objNode.selectNodes("airline");<BR> var objALAttributes = objAirAirline.attributes;<BR> Response.Write ("objAirAirline: " + objALAttributes.getNamedItem("airlinecode").nodeVa lue + "<BR>");<BR><BR> //The error response I get is "objAirAirline is not an object"<BR> <BR>}<BR><BR>I want to use the element that I&#039;m currently working with and access it&#039;s descendants. The objNode.selectNodes() isn&#039;t working, but is there something that will?<BR><BR>Also, does anyone know a good ASP/XML site that has examples of parsing data that are more complex? I&#039;m frustrated by the simple examples given in all of the books.<BR><BR>Thank you!!

  2. #2
    Join Date
    Dec 1969

    Default RE: Parsing complex XML data structure

    Is the airline node an immediate child of the airitem node or is it buried deeper in the tree? If it&#039;s NOT an immediate child try this:<BR><BR>objAirAirline = objNode.selectNodes("//airline");<BR><BR>Dunc<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts