SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 want to generate xml from sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kirank
Starting Member

USA
45 Posts

Posted - 07/22/2012 :  03:16:58  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 07/22/2012 :  06:20:59  Show Profile  Reply with Quote
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
Starting Member

USA
45 Posts

Posted - 07/22/2012 :  07:46:45  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000