Skip to main content
September 24, 2009
Question

Problem with XML replied from web services

  • September 24, 2009
  • 1 reply
  • 603 views

<cfset ServiceResult = "">

<cfset xmltext=xmlParse('<?xml version="1.0" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<runProcess xmlns="http://3e.pl/ADInterface">
<ModelRunProcessRequest>
<ModelRunProcess AD_Process_ID="1000000" AD_Menu_ID="0" AD_Record_ID="0" DocAction="">
  <serviceType>IInvoice</serviceType>
    <ParamValues>
         <field column="DocumentNo">
                <val>#DOCNO_P#</val>
         </field>
    </ParamValues>
  </ModelRunProcess>
<ADLoginRequest>
  <user>WebService</user>
  <pass>WebService</pass>
  <lang>en_US</lang>
  <ClientID>11</ClientID>
  <RoleID>50004</RoleID>
  <OrgID>11</OrgID>
  <WarehouseID>103</WarehouseID>
  <stage />
  </ADLoginRequest>
  </ModelRunProcessRequest>
  </runProcess>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>')>
 

<cfhttp method="post" url="http://192.168.1.11:8080/ADInterface/services/ModelADService">
<cfhttpparam type ="XML" value=#xmltext#>
</cfhttp>

<cfset ServiceResult = cfhttp.fileContent>

from the code above, i will get replied and store into ServiceResult as below

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body><ns1:runProcessResponse
xmlns:ns1="http://3e.pl/ADInterface"><RunProcessResponse
xmlns="http://3e.pl/ADInterface" IsError="false">
<Summary>99 : Transaction Failed C_InvoiceLine</Summary><LogInfo />
</RunProcessResponse></ns1:runProcessResponse></soap:Body></soap:Envelope>

actually what i need is only those information inside the <summary> tag. How can i get the result i need?

Any expert can give their advies? thank you.

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 24, 2009

    You will need to use CF's built-in XML tags and functions. See sample below:

    <cfsavecontent variable="serviceResult"><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body><ns1:runProcessResponse
    xmlns:ns1="http://3e.pl/ADInterface"><RunProcessResponse
    xmlns="http://3e.pl/ADInterface" IsError="false">
    <Summary>99 : Transaction Failed C_InvoiceLine</Summary><LogInfo />
    </RunProcessResponse></ns1:runProcessResponse></soap:Body></soap:Envelope>
    </cfsavecontent>

    <!--- verify content if well formed XML --->
    <cfif IsXml(serviceResult)>

        <!--- create an XML object that CF's XML functions can use --->
        <cfset xmlResult=XmlParse(serviceResult, true) />

        <!--- check for a summary element, will return an array of matching objects
        Note that second parameter for XmlSearch function is an Xpath expresssion
        For an overview of Xpath see http://msdn.microsoft.com/en-us/library/ms256115.aspx
        For seaching XML which uses namespaces in CF see: http://www.coldfusionguy.com/ColdFusion/blog/index.cfm/2008/9/26/XMLSearch-Specify-xmlns-namespaces-in-an-xPath-Search
       
         --->
        <cfset summarySearch=XmlSearch(xmlResult, "//*[local-name()='Summary' and namespace-uri()='http://3e.pl/ADInterface']") />
        <cfif ArrayLen(summarySearch) gt 0>
            Summary found: <cfoutput>#summarySearch[1].XmlText#</cfoutput>
        <cfelse>
            Summary not found
        </cfif>  

    </cfif>