School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,412 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,595 people online right now. Registration is fast and FREE... Join Now!




Traverse XML file returned via SOAP

 

Traverse XML file returned via SOAP, I wouldn't know where to begin

midasxl

5 May, 2009 - 10:38 AM
Post #1

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Hello and thanks for your time (again),
I have an XML file (at least it looks like one) with a whole lot of additional stuff within the syntax which I assume it put there because it is being returned via SOAP. I am trying to figure out how to traverse this xml file to extract the data. I have parsed using xmlParse() to get it down to the XML Document Object structure. I'm not used to targeting the nodes in this manner. Is it as simple as using dot syntax to drill down to the area I need? Every node is called "data". How do I target a node that has the same tag name as every other node?

Check it out...(small snippet)
CODE

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
  <ns1:getSubordinatesResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="ocrs">
   <getSubordinatesReturn xmlns:ns2="http://rpc.xml.coldfusion" xsi:type="ns2:QueryBean">
    <columnList soapenc:arrayType="xsd:string[3]" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:Array">
     <columnList xsi:type="xsd:string">ID</columnList>
     <columnList xsi:type="xsd:string">CMD_TYPE</columnList>
     <columnList xsi:type="xsd:string">PLA</columnList>
    </columnList>
    <data soapenc:arrayType="xsd:anyType[][17]" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:Array">
     <data soapenc:arrayType="xsd:anyType[3]" xsi:type="soapenc:Array">
      <data xsi:type="soapenc:int">1182</data>
      <data xsi:type="soapenc:int">1</data>
      <data xsi:type="soapenc:string">NAVMEDINFOMGTCEN BETHESDA MD</data>
     </data>
     <data soapenc:arrayType="xsd:anyType[3]" xsi:type="soapenc:Array">
      <data xsi:type="soapenc:int">1183</data>
      <data xsi:type="soapenc:int">1</data>
      <data xsi:type="soapenc:string">NAVMEDLOGCOM FT DETRICK MD</data>
     </data>
     <data soapenc:arrayType="xsd:anyType[3]" xsi:type="soapenc:Array">
      <data xsi:type="soapenc:int">1185</data>
      <data xsi:type="soapenc:int">1</data>
      <data xsi:type="soapenc:string">NAVMEDSUPPCOM JACKSONVILLE FL</data>
     </data>
     <data soapenc:arrayType="xsd:anyType[3]" xsi:type="soapenc:Array">
      <data xsi:type="soapenc:int">1186</data>
      <data xsi:type="soapenc:int">1</data>
      <data xsi:type="soapenc:string">NAVMED EAST PORTSMOUTH VA</data>
     </data>
    </data>
   </getSubordinatesReturn>
  </ns1:getSubordinatesResponse>
</soapenv:Body>
</soapenv:Envelope>


I was able to do the following...
CODE

<!--- Read the file and convert it to an XML document object --->
<cfset myDoc=XMLParse("http://localhost:8500/practice/xml/ncdb/ncdb.xml", false)>
<!--- get an array of commands --->
<cfset id = myDoc.XmlRoot.XmlChildren[1].XmlChildren[1].XmlChildren[1].XmlChildren[2].XmlChildren>
<cfdump var="#id#">
<cfset size = ArrayLen(id)>

<cfoutput>
Number of Commands = #size#
<br>
</cfoutput>
<br>
<!--- create a query object with the command data --->
<cfset myquery = QueryNew("id") >
<cfset temp = QueryAddRow(myquery, #size#)>
<cfloop index="i" from = "1" to = #size#>
   <cfset temp = QuerySetCell(myquery, "id",
      #myDoc.XmlRoot.XmlChildren[1].XmlChildren[1].XmlChildren[1].XmlChildren[2].XmlChildren[i]#, #i#)>
</cfloop>

<!--- Dump the query object --->
Contents of the NCDB Query object: <br>
<cfdump var=#myquery#>
<br><br>

Display entire query
<cfquery name="ncdbTest" dbType="query">
   SELECT *
   FROM myquery
</cfquery>

<!--- Dump the query results --->
<cfdump var=#ncdbTest#>


But this just gets all of the data. I want to be able to manipulate different pieces of the data individually. Thanks for an info!

This post has been edited by midasxl: 5 May, 2009 - 10:39 AM

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:11PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month