Solved

Creating XML doc from database record set

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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