?
Solved

Creating XML doc from database record set

Posted on 2003-10-30
3
Medium Priority
?
153 Views
Last Modified: 2013-12-24
Recently I used ColdFusion's WDDX stuff to save the contents of forms to data files. I got to thinking... if I could create an XML document based on the returned recordset of a query, I could feed that XML document into my page layout program (Quark or Indesign) and get a jump-start on the repurposing of that content. This seems pretty simple, but after combing through the books I have, I can't catch on to what I need to do.

Basically, our company has always been Internet based, so our products are all in our SQL database. The online catalog is served up through CF pages. We're now wanting to do a print catalog -- and all the data is there and with a page layout program's ability to handle XML, I know the answer is really close right now!  =-)

Has anyone done this before? How do I dump a recordset out into an XML file?
0
Comment
Question by:alyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:anandkp
ID: 9655806
0
 
LVL 17

Expert Comment

by:anandkp
ID: 9655813
use the logic & create a SP for urself in ur SQL DB ... & it shld create a XML file for u !
0
 
LVL 4

Accepted Solution

by:
procept earned 2000 total points
ID: 9656146
Hi,

how do you want to dump the records? Something like this?

<record>
   <field1>Content1</field1>
   <field2>Content2</field2>
   ...
</record>


Can be done easily with CF MX:

<cfquery name="myQuery" datasource="myDSN">
SELECT *
FROM myTable>
</cfquery>

<cfxml variable="myXMLVar">
   <cfoutput query="myQuery">
      <record>
         <cfloop list="#myQuery.columnList#" index="idx">
         <#idx#>#myQuery[idx][myQuery.currentrow]#</#idx>
      </record>
   </cfoutput>
</cfxml>

Now the whole XML would be in the variable myXMLVar. If you want to store it in a table or write it in a file, you need to use the toString() function:
<cffile action="write" file="C:\myFile.xml" output="#toString(myXMLVar)#" addnewline="no">

HTH,

Chris
0

Featured Post

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question