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
 General SQL Server Forums
 New to SQL Server Programming
 want to generate xml from sql

Author  Topic 

kirank
Yak Posting Veteran

58 Posts

Posted - 2012-07-22 : 03:16:58
want to generate xml from sql , may i know how i can do that using xml for
<?xml version="1.0" encoding="utf-8" ?>
<Merchant>
<item>
<id>139</id>
<url>test-me.aspx</url>
<desc>this is test description </desc>
<pageTitle>Title here </pageTitle>
<pageDesc>Desc here </pageDesc>
<pageKey>Meta here </pageKey>
<MerSeoText>ggB</MerSeoText>
<MerName>Inkfruit</MerName>
<Mdesc>test </Mdesc>
<MdescMore>test test</MdescMore>
<MUrl>www.gg.com</MUrl>
<MUrlWiki>http://en.wikipedia.org/wiki/gg</MUrlWiki>
<MBrandImage>brand_logo1.jpg</MBrandImage>
</item>
<item>
<id>140</id>
<url>test-me.aspx</url>
<desc>this is test description </desc>
<pageTitle>Title here </pageTitle>
<pageDesc>Desc here </pageDesc>
<pageKey>Meta here </pageKey>
<MerSeoText>ggB</MerSeoText>
<MerName>Inkfruit</MerName>
<Mdesc>test </Mdesc>
<MdescMore>test test</MdescMore>
<MUrl>www.gg.com</MUrl>
<MUrlWiki>http://en.wikipedia.org/wiki/gg</MUrlWiki>
<MBrandImage>brand_logo1.jpg</MBrandImage>
</item>
</Merchant>

thank for the help, all the fileds are populating from db.

http://webdevlopementhelp.blogspot.com

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-07-22 : 06:20:59
You would write a select query from your table as you normally would, but then specify XML path with the appropriate node and root names - for example like shown below, where I am showing only 3 columns. You will need to add all the other columns to the select query.
SELECT
id,
url,
desc
FROM
YourTable
FOR XML PATH('item'), ROOT('Merchant');
Go to Top of Page

kirank
Yak Posting Veteran

58 Posts

Posted - 2012-07-22 : 07:46:45
quote:
Originally posted by sunitabeck

You would write a select query from your table as you normally would, but then specify XML path with the appropriate node and root names - for example like shown below, where I am showing only 3 columns. You will need to add all the other columns to the select query.
SELECT
id,
url,
desc
FROM
YourTable
FOR XML PATH('item'), ROOT('Merchant');




yes thankx it works for me :)

---------------------------

http://codingstuffsbykiran.blogspot.com | http://webdevlopementhelp.blogspot.com
Go to Top of Page
   

- Advertisement -