• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Converting this simple XML to a Struct?

New Here ,
Oct 26, 2012 Oct 26, 2012

Copy link to clipboard

Copied

Hi everyone,

I'm having trouble converting this XML to a Struct.

<book_ids quantity="2">7,9</book_ids>

I'm supposed to pass that as a parameter to a remote Web Service using cfinvoke. Can anyone help out on how to convert that XML to a Coldfusion Struct???

Thanks in advance for any help!

JC

Views

890

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 26, 2012 Oct 26, 2012

Copy link to clipboard

Copied

What is the Web Service expecting as a parameter?  More information is needed.

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2012 Oct 26, 2012

Copy link to clipboard

Copied

Hi Carl,

Here's the relevant part of the WSDL:

<s:element name="getBooks">

<s:complexType>

<s:sequence>

<s:element minOccurs="0" maxOccurs="1" name="book_ids" type="tns:BookIDsCollection"/>

</s:sequence>

</s:complexType>

</s:element>

<s:complexType name="BookIDsCollection">

<s:simpleContent>

<s:extension base="s:string">

<s:attribute name="quantity" type="s:int" use="required"/>

</s:extension>

</s:simpleContent>

</s:complexType>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 26, 2012 Oct 26, 2012

Copy link to clipboard

Copied

While I don't have any insight on this (I don't work with web services much), the additional information should make it easier for others to assist you.

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2012 Oct 27, 2012

Copy link to clipboard

Copied

LATEST

You cannot, in general, convert XML into struct. An XML object has elements, which may or may not have attributes. The attributes have values and the element itself may have a "value" in the form of XMLText. Whereas, a struct basically has key-value pairs. As XML packs many more properties that a struct, a one-to-one mapping is often impossible.

In any case, there is little point converting the XML to a struct. A struct is typical ColdFusion lingo that wont be understood by webservices. I would suggest you send the XML itself to the service! How? As a SOAP message.

You could do something like this

!--- Web service WSDL --->

<cfset wsdl_url="http://mydomain.com/myws.cfc?wsdl">

       

<!--- Compose SOAP message to send to web service--->

<cfsavecontent variable="soap"><?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>               

<book_ids quantity="2">7,9</book_ids>               

</soapenv:Body>

</soapenv:Envelope>

</cfsavecontent>

<!--- Invoke web service and send message--->

<cftry>    

        <cfhttp url="#wsdl_url#" method="post" >

            <cfhttpparam type="header" name="content-type" value="text/xml">

            <cfhttpparam type="header" name="SOAPAction" value="">

            <cfhttpparam type="header" name="content-length" value="#len(soap)#">

            <cfhttpparam type="header" name="charset" value="utf-8">

            <cfhttpparam type="xml" name="message" value="#trim(soap)#">

        </cfhttp>

        <p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>

      

    <cfcatch type="any">

        <cfdump var="#cfcatch#">

    </cfcatch>

</cftry>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation