SQL Server – XML Examples(Xpath,Xquery,XML DML,XML Index,XML Schema)

Example 1: Mostly we need  XML in this format,i.e column names with their values enclosed within their column name tag Consider below XML needs to be generated for the below mentioned sample table definition <Employee> <field Name=“ID“>1</field><field Name=“Name“>Sathya</field><field Name=“Age“>25</field><field Name=“Sex“>Male</field><field Name=“ID“>2</field><field Name=“Name“>Sunny</field><field Name=“Age“>24</field><field Name=“Sex“>Female</field></Employee> DECLARE @Employee TABLE (ID INT,Name VARCHAR(100),Age INT,Sex VARCHAR(50)) INSERT @Employee SELECT 1,‘Sathya’,25,‘Male’INSERT…

Details

XQUERY,XPATH,XMLSCHEMA,XML INDEX

(XQUERY,XPATH,XMLSCHEMA,XML INDEX) Ø  XQuery is the language for querying XML data.    Ø  XPath was designed to navigate an XML document to retrieve the documents elements and attributes.      Ø  XQuery is built on XPath expressions. Ø To put it simple XQuery,XPath are used to traverse through XML document/fragment to fetch/modify attribute values or element…

Details