Saturday, June 22, 2013

Coldfusion read xml from asp webservices

what can you do if you have a webservices from asp that display info in a xlm text? how do you get the data from the file?


<cfset ws = createObject("webservice","http://110.111.11.88/WEBSERVICE/INTERIMWEBSERVICE.ASMX?WSDL") />
<cfset result = ws.view_interim("No","JGT4") />

<cfset dataset = result >
<cfset  result = structNew() /> 
<cfset  aDataset = dataset.get_any() /> 
<cfset  xSchema = xmlParse(aDataset[1]) /> 


<!---please understand what is the reason to do this--->
<cfset  xTables = xSchema["xs:schema"] ["xs:element"]["xs:complexType"]["xs:choice"] /> 

<cfset  xData = xmlParse(aDataset[2]) /> 

<!---please understand what the reason to do this--->
<cfset  xRows = xData["diffgr:diffgram"] ["DocumentElement"]  /> 


<cfset  tableName = "" /> 
<cfset  thisRow = "" /> 
<cfset  i = "" /> 
<cfset  j = "" /> 

<cfset FIELD_NAME = ARRAYNEW(1)> 
<cfset FIELD_VALUE = ARRAYNEW(1)> 

<cfoutput>

<cfset jLoop = 0>

<cfloop from="1" to="#arrayLen(xTables.xmlChildren)#" index="i"> 

<cfset tableName = xTables.xmlChildren[i].xmlAttributes.name /> 
<cfset xColumns = xTables.xmlChildren[i].xmlChildren[1].xmlChildren[1].xmlChildren/> 
  <cfset result[tableName] = queryNew("") /> 
<cfloop from="1" to="#arrayLen(xColumns)#" index="j"> 
<!---<cfset queryAddColumn(result[tableName], xColumns[j].xmlAttributes.name, arrayNew(1)) /> --->
<CFSET FIELD_NAME[j] = TRIM(#xColumns[j].xmlAttributes.name# )>
<cfset jLoop = #jLoop# + 1>
</cfloop>  
</cfloop>  

<!--- Populate Queries ---> 
<cfloop from="1" to="#arrayLen(xRows.xmlChildren)#" index="i"> 
<cfset thisRow = xRows.xmlChildren[i] /> 
<cfset thisRowText = xRows.xmlChildren[i].xmlText /> 
<cfset tableName = thisRow.xmlName /> 
   <!--- <cfset queryAddRow(result[tableName], 1) /> --->
   tableName : #tableName# - thisRowText : #thisRowText# - 
<cfloop from="1" to="#arrayLen(thisRow.xmlChildren)#" index="j"> 
<!---<cfset querySetCell(result[tableName], thisRow.xmlChildren[j].xmlName, thisRow  .xmlChildren[j].xmlText, result[tableName].recordCount) /> --->
<!---j : #j# - #thisRow.xmlChildren[j].xmlText#/ --->
<CFSET FIELD_VALUE[j] = TRIM(#thisRow.xmlChildren[j].xmlText#) >
</cfloop> 
<br />
</cfloop>  
<cfloop from="1" to="#jLoop#" index="i"> 
#i#. #FIELD_NAME[i]# : #FIELD_VALUE[i]# <br /> 
</cfloop> 

</cfoutput>


==============================


COLDFUSION ROCKS!


0 comments:

Post a Comment

Say whut you want, but be responsible on whut you said...