- SQL Result is convert into XML Formate using XML clause.
- XML clause only used in the select statement in subqueries.
- XML clause used in (INSERT,UPDATE,DELETE) statements.
Here Are three mode used in XML clause.
- RAW
- Auto
- Path
1.RAW
Description: Every row in your table is convert result set of XML node. user can also change all node name.and column is also converted into attribute.
Example:
select Product_ID, Name, Price from Product for xml raw
Result:
Generate XML Result:
<row Product_ID="1" Name="Table" Price="100" /> <row Product_ID="2" Name="Chair" Price="900" />
2. Auto
Description: Here table name is used row name insted of row.
Example:
select Product_ID, Name, Price from Product for xml auto
Result:
Generate XML Result:
<Product Product_ID="1" Name="Table" Price="100" /> <Product Product_ID="2" Name="Chair" Price="900" />
3. Path
Description: Here Every Record is a Parent element, and every column is nested element, If you can also set the custome attribute.
Example:
select Product_ID, Name, Price from Product for xml path
Result:
<row> <Product_ID>1</Product_ID> <Name>Table</Name> <Price>100</Price> </row> <row> <Product_ID>2</Product_ID> <Name>Chair</Name> <Price>900</Price> </row>