Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how do i add a root to an xml output from microsoft sql?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-03 : 08:02:34
karthik writes "i have a task of integrating sql, xml, xslt, html using .net.
for my xslt to transform an xml, the xml must have a root element at the start and end of the xml. but on using " for xml auto, ELEMENTS " in the query, i do not get a root element.

let me explain my problem with an example using the NORTHWIND database.
my sql query
"select customerid, contactname, postalcode,country from customers where country = 'mexico' for xml auto, elements"

this gives me the output:

<customers>
<customerid>ANATR</customerid>
<contactname>AnaTrujillo</contactname>
<postalcode>05021</postalcode>
<country>Mexico</country>
</customers>
<customers>
<customerid>ANTON</customerid>
<contactname>AntonioMoreno</contactname>
<postalcode>05023</postalcode>
<country>Mexico</country>
</customers>
<customers>
<customerid>CENTC</customerid>
<contactname>FranciscoChang</contactname>
<postalcode>05022</postalcode>
<country>Mexico</country>
</customers>
<customers>
<customerid>PERIC</customerid>
<contactname>GuillermoFernández</contactname>
<postalcode>05033</postalcode>
<country>Mexico</country>
</customers>
<customers>
<customerid>TORTU</customerid>
<contactname>Miguel Angel Paolino</contactname>
<postalcode>05033</postalcode>
<country>Mexico</country>
</customers>

this cannot be transformed by an xsl because there is no root element. the <customers> is not the root because it appears for all customers.

is there a any way i could get a root element appended to my xml?"

Kristen
Test

22859 Posts

Posted - 2005-08-03 : 15:18:56
Welcome to SQL Team karthik!

I answered a similar question the other day, please see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53050 and ask a further question if that doesn't provide an answer

Kristen
Go to Top of Page

kbcde
Starting Member

1 Post

Posted - 2005-08-04 : 00:34:36
hey Kristen, that solved my problem. thanks a million. Amazing.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-04 : 01:00:39
"Amazing"

I very much doubt it ... but thanks for taking the trouble to come back and say "Thanks" - particularly as I guess you had to register to do so.

Kristen
Go to Top of Page
   

- Advertisement -