Introduction
We can convert the data table into XML format using.
- XML Raw
- XML Path
- XML Auto
Here I am going to use XML Raw to convert the data table to XML format.
1.XML Raw
RAW mode transforms each row in the query result into an XML element.
This is my table structure.
The query is to convert the data table to XML format.
select*from Products for xml raw('Products'),root('ProductDetails')
Result
<ProductDetails>
<Products id="1" Name="T-shirts" Category="Mens Clothing" />
<Products id="2" Name="Track Suit" Category="Mens Clothing" />
<Products id="3" Name="Shoes" Category="Mens Footwear" />
<Products id="4" Name="Sandals" Category="Mens Footwear" />
</ProductDetails>
2. XML Path
The query is to convert the data table to XML format.
select*from Products for xml path('Products'),root('ProductDetails')
Result
<ProductDetails>
<Products>
<id>1</id>
<Name>T-shirts</Name>
<Category>Mens Clothing</Category>
</Products>
<Products>
<id>2</id>
<Name>Track Suit</Name>
<Category>Mens Clothing</Category>
</Products>
<Products>
<id>3</id>
<Name>Shoes</Name>
<Category>Mens Footwear</Category>
</Products>
<Products>
<id>4</id>
<Name>Sandals</Name>
<Category>Mens Footwear</Category>
</Products>
</ProductDetails>
3. XML Auto
The query is to convert the data table to XML format.
select*from Products for xml auto,root('ProductDetails')
Result
<ProductDetails>
<Products id="1" Name="T-shirts" Category="Mens Clothing" />
<Products id="2" Name="Track Suit" Category="Mens Clothing" />
<Products id="3" Name="Shoes" Category="Mens Footwear" />
<Products id="4" Name="Sandals" Category="Mens Footwear" />
</ProductDetails>
Conclusion
From this blog, we taught how to convert the data table to XML using XML Raw, XML path, and XML Auto.

Hardik ShahPosted Jul 15, 2019, 1:50 PM
This shows how to export data to XML. How can I import same XML data into table?
Bharatbhushan SharmaPosted Jun 13, 2018, 2:31 AM
Useful Information
Hashim ShafiqPosted Aug 30, 2015, 9:38 PM
nice
Pankaj Kumar ChoudharyPosted Aug 30, 2015, 12:47 PM
Thanks Gowtham K for Explanation now it provide better understanding the diff b/w row and auto method.....
Pankaj Kumar ChoudharyPosted Aug 30, 2015, 6:20 AM
Hello! Gowtham K Sir can you explain what is diff b/w first(row) and last(auto) method. This article might be more better if you provided more details about each method....
Pankaj Kumar ChoudharyPosted Aug 30, 2015, 6:13 AM
Nice Explain Sir..........
Santhakumar MunuswamyPosted Aug 30, 2015, 5:04 AM
Nice share