Articles → XSD → Introduction To XSD

Introduction To XSD








What Is XSD?







Back To Basics - Types Of XML Element




  1. Simple element – Simple elements are those XML elements which don’t have child elements or attributes.
  2. <element_name>text</element_name>


  3. Complex element – Complex elements are those XML elements which contain child elements or attributes.
  4. <element_name attribute1=”attribute_value”>
    .. Child nodes or text
    </element_name>



Validate XML Against XSD






  1. Open query analyzer
  2. Write following code
  3. -- 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




  4. Run the query.



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




  1. string
  2. decimal
  3. integer
  4. boolean
  5. date
  6. time

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