Converting Table data into XML format using FOR XML clause.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 939
For All Table records
Select(Select * from test1 Order By ID FOR XML AUTO, ELEMENTS XSINIL);


Output:-
<test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>1</ID>
<Name>Test1</Name>
<Address>Nagpur</Address>
</test1>
<test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>2</ID>
<Name>Test1</Name>
<Address>Nanded</Address>
</test1>
<test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>3</ID>
<Name>Test1</Name>
<Address>Pune</Address>
</test1>
<test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>4</ID>
<Name>Test1</Name>
<Address>Jabalpur</Address>
</test1>


For specific record
Select(Select * from test1 WHERE ID = 1 Order By ID FOR XML AUTO, ELEMENTS XSINIL);


<test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>1</ID>
<Name>Test1</Name>
<Address>Nagpur</Address>
</test1>

Comments or Responses

Login to post response