Skip to main content
Participant
December 8, 2009
Question

How Can i create this especific xml using structNew()?

  • December 8, 2009
  • 1 reply
  • 963 views

Hi everyone!

I'm starting my first steps using coldfusion technology and i have been facing some problems when i try to create a client that consumes my webservices.

What i trying to do is:

to create this kind of xml structure:

<elem att1="1" att2="2"/>

i use this coldfusion code:

elem= structNew();
elem.att1= "1";
elem.att2= "2";

But, what if i want to create this kind of structure

<elem att1="1" att2="2">ELEMENT VALUE</elem>

what can i do to insert the element value "ELEMENT VALUE"

I tried structInsert, but i don't think it'll help me.

Thank in advance,

Felipe

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    December 8, 2009

    While arrays, structures and XML data share similar syntax and concepts, they are not the same data types.

    You need to look at the XML functions not the structure functions.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_21.html#3468770

    http://livedocs.adobe.com/coldfusion/8/htmldocs/XML_02.html#1126735

    One of the simplest ways to create an xml structure like you are attempting would be the <cfxml...> tag.

    <cfxml variable="myXMLobj">

    <elem att1="1" att2="2">ELEMENT VALUE</elem>

    </cfxml>

    But this is by no means the only way to skin this xml cat in ColdFusion.

    Participant
    December 8, 2009

    Thanks for the answer Ian. But is it possible to consume a websevices using  CreateObject synthax and  XML object instead a struct  object?

    XMLData = XMLNew();

     ...

    ws = createObject("webservice", "http://www.somedomain.com/soap/somefile.wsdl");

    return = ws.getWSSomething(XMLData);

    i followed this example that shows how to consume a webservices

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-78b4.html

    but it doesn't say nothing about  how to set node values, just attribute values.

    thanks again

    Felipe

    ilssac
    Inspiring
    December 8, 2009

    webservices can consume and deliver any type of data from simple integers to structures, recordsets or xml.

    xml can be used in many ways completely unrealted to web services.

    So you really have two different problems here that are only related because you want them to be for your task at hand.

    An abosultely barebones, do nothing, completely untested example:

    webservice.cfm

    <cfcomponent>
      <cffunction name="getSomeXML" access="remote" returntype="xml">
      <cfset var returnxml = "">
        <cfxml variable="returnxml">
        <foo>
          <bar param1="George" param2="Gracie">Say goodnight Gracie</bar>
        </foo>
       </cfxml>
       <cfreturn returnxml>
       </cffunction>
    </cfcomponent>

    consumer.cfm

    <cfset ws = createObject("webservice", "http://www.somedomain.com/soap/somefile.wsdlwerbservice.cfm")<

    <cfset theXML = ws.getSomeXML()>

    <cfdump var="#theXML#">

    What happens after this depens on are you writting the webservice, consuming the webservice or both.  Are you passing in XML or passing out XM. And other factors.