Professional Web Applications Themes

Generate XML from CFC...HELP - Coldfusion - Advanced Techniques

Can any of you CF experts help me visualize how a CFC needs to look to generate XML? Do I need to use CF tags to create the XML within a query and return it as a string ?? I also need to have a CFC to take an XML file and p it within the service. A simple sample would be ideal otherwise I could get by with some hand holding. TIA...

  1. #1

    Default Generate XML from CFC...HELP

    Can any of you CF experts help me visualize how a CFC needs to look to generate
    XML? Do I need to use CF tags to create the XML within a query and return it
    as a string ??

    I also need to have a CFC to take an XML file and p it within the service.

    A simple sample would be ideal otherwise I could get by with some hand holding.

    TIA

    cfhottie Guest

  2. #2

    Default Re: Generate XML from CFC...HELP

    this depends on how you are building the xml from the query? how is the result
    set going to look like? once you know this, what you can do is to have a
    cfsavecontent variable with this xml doent... After call the method in your
    cfc that will read and p it.. something like

    <cfset readMyXml(myXMLvar)>

    in the CFC method itself you can have a required argument of type any. Let me
    know if it makes sense.

    adonis1976 Guest

  3. #3

    Default Re: Generate XML from CFC...HELP

    What I would like to do is to have a CFC receive an arguement and run a query.
    Produce the results of the query in an XML format.

    Conversely, I need a CFC to receive an XML file, and execute a query to update
    a database table for the XML doc it receives. I am basically starting out with
    this and would prefer a straight forward, basic sample.

    I am just having trouble getting the whole job started. I feel a bit
    intimidated by the web service and XML.

    :confused;

    cfhottie Guest

  4. #4

    Default Re: Generate XML from CFC...HELP

    It's easy to do. Here's an example:

    <cfcomponent output="no" displayname="Books">

    <cffunction access="remote" name="getEvaluation" returntype="string">
    <cfargument name="Id" type="numeric" required="yes">

    <cfquery datasource="your_datasource" name="thisQuery">
    select id, name, title
    from books
    where id = <cfqueryparam type="cf_sql_bigint" value="#id#">
    </cfquery>

    <cfxml variable="XMLEval">
    <books>
    <cfoutput query="thisQuery">
    <book_detail>
    <book_id id="#thisQuery.id#"/>
    <name>#thisQuery.name#</namd>
    <title>#thisQuery.title#</title>
    </book_detail>
    </cfoutput>
    </books>
    </cfxml>
    <cfset XMLString = toString(XMLBooks)>

    <cfreturn XMLBooks>
    </cffunction>

    </cfcomponent>

    jim1234 Guest

  5. #5

    Default Re: Generate XML from CFC...HELP

    Hi there,

    Just a quick additon. Depending on how you create you xml and how picky the
    your target xml pr is, you can run into problems with whitespace existing
    before your xml declaration. If you run into this problem you can sidestep it
    as follows:

    #Trim(ToString(insertnameofxmldoenthere)#

    lad4bear Guest

  6. #6

    Default Re: Generate XML from CFC...HELP

    :)

    Many thanks to the awesome guys who responded, especially, jim1234 and lad4bear. It made the approach I need to take quite clear.
    developwin Guest

Similar Threads

  1. How do you generate a connection key?
    By Wodehouse in forum Macromedia Contribute Connection Administrtion
    Replies: 1
    Last Post: March 21st, 09:11 AM
  2. what kind of .txt does CF generate?
    By AkronNick in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 8th, 04:11 AM
  3. How to generate pie slices?
    By Paket in forum Macromedia Director 3D
    Replies: 0
    Last Post: June 29th, 03:56 AM
  4. Using SQL to generate SQL and execute it
    By Evan Smith in forum IBM DB2
    Replies: 2
    Last Post: July 16th, 01:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139