Articles → XSD → Introduction to xsd

Introduction to xsd








What is XSD?







Back to basics - types of XML element






<element_name>text</element_name>




<element_name attribute1=”attribute_value”>
.. Child nodes or text
</element_name>



Validate XML against XSD










-- Create a XML schema collection
Create XML schema collection TestSchemaCollection As '
XSD ' -- XSD against which XML will be validated 
GO

--  Create a table with a single column of data type XML
Create table TestTable
(
	MyXMLSample XML (TestSchemaCollection) 
)

-- Insert a XML into the table
-- Insertion will be success if XML is valid
-- else insert statement will throw an error.
Insert into TestTable values('XML')

-- Finally drop a table and XML schema collection
drop table TestTable
drop xml schema collection TestSchemaCollection









Schema element in XSD






<schema xmlns="http://www.w3.org/2001/XMLSchema">
..
</schema>



Simple XML element in XSD




<element name="element_name" type="data_type" />





Complex XML element in XSD






<element name="name_of_complex_element">
	<complexType>
		<group_indicator>
        .. 
        List of simple types of xml elements
     
		</ group_indicator>
	</complexType>
</element> 





XML attributes in XSD




<attribute name="" type=""/>



Data types supported by XSD

















Examples






<Blogs>
	<blog category="Technical">
		<title>Code Project</title>
		<URL>CodeProject.com</URL>
	</blog>
</Blogs>




<schema
	xmlns="http://www.w3.org/2001/XMLSchema">
	<element name="Blogs">
		<complexType>
			<sequence>
				<element name="blog">
					<complexType>
						<sequence>
							<element name="title" type="string" />
							<element name="URL" type="string" />
						</sequence>
						<attribute name="category" type="string"/>
					</complexType>
				</element>
			</sequence>
		</complexType>
	</element>
</schema>





Posted By  -  Karan Gupta
 
Posted On  -  Sunday, January 4, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250