Traverse XML file returned via SOAP

I wouldn't know where to begin

Page 1 of 1

0 Replies - 2583 Views - Last Post: 05 May 2009 - 11:38 AM Rate Topic: -----

#1 midasxl   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 215
  • Joined: 03-December 08

Traverse XML file returned via SOAP

Post icon  Posted 05 May 2009 - 11:38 AM

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)
<?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...
<!--- 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: 05 May 2009 - 11:39 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1