Solved

Creating XML doc from database record set

Posted on 2003-10-30
3
151 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 500 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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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