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

Use Query Results as XML?

Community Beginner ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

489

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

correct answers 1 Correct answer

Community Beginner , Mar 21, 2009 Mar 21, 2009
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

Votes

Translate

Translate
Advisor ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

Please post your code and the error messages, if any, you are seeing.

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 Beginner ,
Mar 20, 2009 Mar 20, 2009

Copy link to clipboard

Copied

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

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
Advisor ,
Mar 21, 2009 Mar 21, 2009

Copy link to clipboard

Copied

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.

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 Beginner ,
Mar 21, 2009 Mar 21, 2009

Copy link to clipboard

Copied

LATEST
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

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
LEGEND ,
Mar 21, 2009 Mar 21, 2009

Copy link to clipboard

Copied

"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

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