5 Replies Latest reply on Mar 21, 2009 10:29 AM by TomNez

    Use Query Results as XML?

    TomNez
      Hey all, I searched the forums but didn't find anything that quite fit this particular issue, I'm hoping someone can help me out.

      I am storing a string of text in a database field. It's an XML string (not technically, but it's formatted to BE xml).

      I am pulling this from the database in ColdFusion and trying to use it as XML, but having no luck. I can get as far as pulling it and dumping the data and I get this:

      <root><Booleanval>on</Booleanval><SuperDooperSelector>1</SuperDooperSelector><ContentBody> words</ContentBody><ContentTitle>AWESOME</ContentTitle><DocumentName>Content 1</DocumentName></root>

      It's a test so the values are a bit goofy but it appears as it should nonetheless. I am wondering if there is a way I can parse this into actual XML and access these attributes the same way I normally would in ColdFusion. It won't let me use XMLParse(#myvar#) because it is technically a query.

      Does anyone know how I can use this data as XML in ColdFusion?
        • 1. Re: Use Query Results as XML?
          JR "Bob" Dobbs-qSBHQ2 Level 3
          Please post your code and the error messages, if any, you are seeing.
          • 2. Re: Use Query Results as XML?
            TomNez Level 1
            Hello,

            Here's how it's happening:

            The first code I attached at the bottom is my component that runs a query on the database. This returns "productData" which is just a string of XML formatted text (you can see this string in my first post starting with <root>). However ColdFusion is obviously reading it as being a query and not a string, which is my problem.

            Then, in the page where I call the function, I have this code:

            <cfdump var="xmlParse(#productData#)">

            But I get this error:

            "Complex object types cannot be converted to simple values. "

            I do see and understand the problem, I just don't know how to fix it :/ If you can offer any help or suggestions as to how I can pull this data from the database and convert it to a string of XML, I would definitely appreciate it. Our other programmer built the database this way and it's turning out to be a headache.

            Thanks,
            Tom
            • 3. Re: Use Query Results as XML?
              JR "Bob" Dobbs-qSBHQ2 Level 3
              I think that you need to pass only the value of the column containing the XML string to XmlParse(), not the entire query object.

              Try something like: <cfset myxml=XmlParse(productData.contentHistory) />

              If this doesn't work please post the code that invokes getProducts.
              • 4. Re: Use Query Results as XML?
                Level 7
                "TomNez" <webforumsuser@macromedia.com> wrote in message news:gpu7r7$h18$1@forums.macromedia.com...
                > Hey all, I searched the forums but didn't find anything that quite fit this
                > particular issue, I'm hoping someone can help me out.
                >
                > I am storing a string of text in a database field. It's an XML string (not
                > technically, but it's formatted to BE xml).
                >
                > I am pulling this from the database in ColdFusion and trying to use it as XML,
                > but having no luck. I can get as far as pulling it and dumping the data and I
                > get this:
                >
                >
                > <root><Booleanval>on</Booleanval><SuperDooperSelector>1</SuperDooperSelector><Co
                > ntentBody>words</ContentBody><ContentTitle>AWESOME</ContentTitle><DocumentName>C
                > ontent 1</DocumentName></root>
                >
                > It's a test so the values are a bit goofy but it appears as it should
                > nonetheless. I am wondering if there is a way I can parse this into actual XML
                > and access these attributes the same way I normally would in ColdFusion. It
                > won't let me use XMLParse(#myvar#) because it is technically a query.
                >
                > Does anyone know how I can use this data as XML in ColdFusion?
                >


                See if this helps:

                http://labs.adobe.com/technologies/spry/samples/utils/query2xml.html

                --
                Ken Ford
                Adobe Community Expert - Dreamweaver/ColdFusion
                Adobe Certified Expert - Dreamweaver CS3
                Adobe Certified Expert - ColdFusion 8
                Fordwebs, LLC
                http://www.fordwebs.com
                http://www.cfnoob.com

                • 5. Re: Use Query Results as XML?
                  TomNez Level 1
                  Dobbs! I can't believe I missed that. Yes, that was the solution. Thank you for pointing it out. Since my query was only returning one field I didn't think to specify it and was trying to use the entire results.

                  @Ken - Thanks for the link. I checked it out but that seems like it's for taking non xml formatted data and formatting it. Mine is already formatted as XML and stored in a db field.

                  Thanks everyone. I much appreciate you taking your time to help a total noob :P

                  -Tom