Home All Groups Group Topic Archive Search About

Exporting to an XML file

Author
20 May 2009 8:03 PM
TLuebke

My first time exporting XML via SQL 2005. Searching the net I found a proc
but it doesn't format the file correctly

Running this:
sp_makewebtask @outputfile = 'c:\temp\myxmlfile.xml',
    @query = 'SELECT rtrim(cust_ID) AS "Role ID", rtrim(LASTNAME) AS LName,
rtrim(FIRSTNAME) AS Fname FROM web_met for xml auto', 
    @templatefile = 'c:\temp\template.tpl'

Produces this:

<?xml version="1.0"?>
<root><web_met Role_x0020_ID="11111111" LName="Boxer" Fname="Ima"/><web_met
Role_x0020_ID="22222222" LName="Louis" Fname="Joe"/>
<root>

What I need is this:

<?xml version="1.0"?>
<root>
<row id="11111111" lname="Boxer" fname="Ima"/>
<row id="22222222" lname="Louis" fname="Joe"/>
<root>

I see there are several approaches to creating XML files. What is the
quickest and least complex method to make a simple XML in the required format?

Author
21 May 2009 10:34 AM
Bob
Try this SQL, instead of yours:

SELECT cust_ID AS id, LASTNAME AS lname, FIRSTNAME AS fname
FROM #web_met
FOR XML RAW, ROOT('root')

HTH
wBob

Show quoteHide quote
"TLuebke" wrote:

> My first time exporting XML via SQL 2005. Searching the net I found a proc
> but it doesn't format the file correctly
>
> Running this:
> sp_makewebtask @outputfile = 'c:\temp\myxmlfile.xml',
>     @query = 'SELECT rtrim(cust_ID) AS "Role ID", rtrim(LASTNAME) AS LName,
> rtrim(FIRSTNAME) AS Fname FROM web_met for xml auto', 
>     @templatefile = 'c:\temp\template.tpl'
>
> Produces this:
>
> <?xml version="1.0"?>
> <root><web_met Role_x0020_ID="11111111" LName="Boxer" Fname="Ima"/><web_met
> Role_x0020_ID="22222222" LName="Louis" Fname="Joe"/>
> <root>
>
> What I need is this:
>
> <?xml version="1.0"?>
> <root>
> <row id="11111111" lname="Boxer" fname="Ima"/>
> <row id="22222222" lname="Louis" fname="Joe"/>
> <root>
>
> I see there are several approaches to creating XML files. What is the
> quickest and least complex method to make a simple XML in the required format?
Are all your drivers up to date? click for free checkup

Author
21 May 2009 2:35 PM
TLuebke
Bob,
  Thanks - that was slick :)   how do I get the: <?xml version="1.0"?> on
top and the whole thing into a saved text file?


Show quoteHide quote
"Bob" wrote:

> Try this SQL, instead of yours:
>
> SELECT cust_ID AS id, LASTNAME AS lname, FIRSTNAME AS fname
> FROM #web_met
> FOR XML RAW, ROOT('root')
>
> HTH
> wBob
>
> "TLuebke" wrote:
>
> > My first time exporting XML via SQL 2005. Searching the net I found a proc
> > but it doesn't format the file correctly
> >
> > Running this:
> > sp_makewebtask @outputfile = 'c:\temp\myxmlfile.xml',
> >     @query = 'SELECT rtrim(cust_ID) AS "Role ID", rtrim(LASTNAME) AS LName,
> > rtrim(FIRSTNAME) AS Fname FROM web_met for xml auto', 
> >     @templatefile = 'c:\temp\template.tpl'
> >
> > Produces this:
> >
> > <?xml version="1.0"?>
> > <root><web_met Role_x0020_ID="11111111" LName="Boxer" Fname="Ima"/><web_met
> > Role_x0020_ID="22222222" LName="Louis" Fname="Joe"/>
> > <root>
> >
> > What I need is this:
> >
> > <?xml version="1.0"?>
> > <root>
> > <row id="11111111" lname="Boxer" fname="Ima"/>
> > <row id="22222222" lname="Louis" fname="Joe"/>
> > <root>
> >
> > I see there are several approaches to creating XML files. What is the
> > quickest and least complex method to make a simple XML in the required format?
Author
21 May 2009 4:59 PM
TLuebke
I got it. I realized that you wanted me to switchout the sql but retain the
other snippet of code.  Thanks again for the help

Show quoteHide quote
"TLuebke" wrote:

> Bob,
>   Thanks - that was slick :)   how do I get the: <?xml version="1.0"?> on
> top and the whole thing into a saved text file?
>
>
> "Bob" wrote:
>
> > Try this SQL, instead of yours:
> >
> > SELECT cust_ID AS id, LASTNAME AS lname, FIRSTNAME AS fname
> > FROM #web_met
> > FOR XML RAW, ROOT('root')
> >
> > HTH
> > wBob
> >
> > "TLuebke" wrote:
> >
> > > My first time exporting XML via SQL 2005. Searching the net I found a proc
> > > but it doesn't format the file correctly
> > >
> > > Running this:
> > > sp_makewebtask @outputfile = 'c:\temp\myxmlfile.xml',
> > >     @query = 'SELECT rtrim(cust_ID) AS "Role ID", rtrim(LASTNAME) AS LName,
> > > rtrim(FIRSTNAME) AS Fname FROM web_met for xml auto', 
> > >     @templatefile = 'c:\temp\template.tpl'
> > >
> > > Produces this:
> > >
> > > <?xml version="1.0"?>
> > > <root><web_met Role_x0020_ID="11111111" LName="Boxer" Fname="Ima"/><web_met
> > > Role_x0020_ID="22222222" LName="Louis" Fname="Joe"/>
> > > <root>
> > >
> > > What I need is this:
> > >
> > > <?xml version="1.0"?>
> > > <root>
> > > <row id="11111111" lname="Boxer" fname="Ima"/>
> > > <row id="22222222" lname="Louis" fname="Joe"/>
> > > <root>
> > >
> > > I see there are several approaches to creating XML files. What is the
> > > quickest and least complex method to make a simple XML in the required format?

Bookmark and Share