Solved

Creating XML doc from database record set

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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

12 Experts available now in Live!

Get 1:1 Help Now