Solved

Creating XML doc from database record set

Posted on 2003-10-30
3
146 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
  • 2
3 Comments
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
0
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now