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="" xmlns:xsd="" xmlns:xsi="">
  <ns1:getSubordinatesResponse soapenv:encodingStyle="" xmlns:ns1="ocrs">
   <getSubordinatesReturn xmlns:ns2="http://rpc.xml.coldfusion" xsi:type="ns2:QueryBean">
	<columnList soapenc:arrayType="xsd:string[3]" xmlns:soapenc="" 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>
	<data soapenc:arrayType="xsd:anyType[][17]" xmlns:soapenc="" 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 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 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 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>

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

Number of Commands = #size#
<!--- 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#)>

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

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

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