Skip to main content
March 19, 2009
Answered

Use Query Results as XML?

  • March 19, 2009
  • 2 replies
  • 642 views
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?
This topic has been closed for replies.
Correct answer
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.

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

2 replies

Inspiring
March 21, 2009
"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

Inspiring
March 19, 2009
Please post your code and the error messages, if any, you are seeing.
March 20, 2009
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
Inspiring
March 21, 2009
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.