The following is an example of how to create an XML Schema in SQL Server.
1: -- DROP IF EXISTS
2: IF EXISTS (SELECT 1
3: FROM sys.xml_schema_collections
4: WHERE name='SampleSchema')
5: DROP XML SCHEMA COLLECTION SampleSchema
6:
7: CREATE XML SCHEMA COLLECTION SampleSchema AS
8: '<?xml version="1.0" encoding="utf-8"?>
9: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
10: <xsd:element name="Sample">
11: <xsd:complexType>
12: <xsd:attribute name="SampleID" type="xsd:integer" />
13: <xsd:attribute name="Name" type="xsd:string" />
14: <xsd:attribute name="Description" type="xsd:string" />
15: </xsd:complexType>
16: </xsd:element>
17: </xsd:schema>'
To check your XML Schema:
Method 1: Go to your database > Programmability > Types > XML Schema Collections
Method 2: You can use the xml_schema_namespace function to query the schema from within SSMS
1:
2: SELECT
3: xml_schema_namespace(N'dbo',N'SampleSchema')
Later on I will post additional sample schemas which use different SQL XML data types.
SQLXML : How to Create an XML Schema,Filed under:
SQLXML
-my schema it’s correct?
If I want to read xml data from a string like the one struck down.
—- string xml
134234345
7345fgdfg
15/02/2011
9:30 am