Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi friends,


I'm new to xml sql. I need to generate a xml file from sql script in such a that
XML
<country name="INDIA">
        <state>Andhra Pradesh</state>
        <state>Arunachal Pradesh</state>
        <state>Assam</state>

How can write a script for getting this.
Posted
Comments
Sergey Alexandrovich Kryukov 14-Dec-11 0:03am    
OK, this is the sample of output. What was supposed to by on input? A script?! How and what is it? More importantly -- why?
--SA
jagadeesh123qqq 14-Dec-11 0:09am    
Thanks for your reply...
My script is ...
SELECT Col_code,Col_name FROM
(select D.dist_name,C.Col_code,Col_name from college C
INNER JOIN District D oN C.District=D.Dist_code) D
where Dist_name LIKE 'Baga%'
GROUP BY Dist_name,Col_code,Col_name

For XML AUTO,ELEMENTS

i am binding list of colleges at client side to dropdownlist


1 solution

If you have AdventureWorks DB installed then try to use SQL statement to learn producing XML output :

SQL
USE AdventureWorks
SELECT
(
SELECT TOP 2
'AdventureWorks' AS '@Table'
,'E' AS '@ChangeType'
,'ContactID' AS 'Column/@Name'
, c.ContactID AS 'Column/*'
, NULL
,'FirstName' AS 'Column/@Name'
, c.FirstName AS 'Column/*'
, NULL
,'LastName' AS 'Column/@Name'
, c.LastName AS 'Column/*'
, NULL
,'Phone' AS 'Column/@Name'
, c.Phone AS 'Column/*'
, NULL
FROM Person.Contact c
ORDER BY ContactID
FOR XML PATH('DataRow'), Type
)
FOR XML PATH('Root')


Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900