A Tutorial on XSD Files
You create an XML Schema Document (XSD) any time you want to enforce a valid schema within your XML documents. The purpose of the XSD is to ensure that any XML document calling that XSD is well-formed, and that only permitted elements and attributes are added to the document. The XSD also ensures all XML documents created or used by a software application can communicate with other applications as expected, and that the data communication is secure between applications.
Instructions
-
Create New Web Project
-
1
Click the "Start" menu, "All Programs" and click "Microsoft Visual Studio 2010."
-
2
Click "New Web Project" from the "File" menu.
-
-
3
Click "ASP.NET Empty Web Project" from the list of templates and enter a name of your choice in the text box provided.
-
4
Click the "OK" button.
Add XML Files
-
5
Right-click the project name in the Solution Explorer.
-
6
Click "Add," then "New Item..." from the menu.
-
7
Click "XML File" from the list and click the "OK" button.
-
8
Click "Add," then "Folder" and name the folder "XSchema."
-
9
Right-click on the "XSchema" folder; click "Add" and then "New Item..." from the menu.
-
10
Click to highlight "XML File" and change the .XML extension to .XSD; then click the "OK" button.
Write the XML Tags
-
11
Double-click the "XmlFile2.xsd" file and type the following:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="customer">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string" />
<xsd:element name="lastname" type="xsd:string" />
<xsd:element name="joindate" type="xsd:date" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
-
12
Double-click the XmlFile1.xml" file and type the following where "server_name" is the domain_name is the DNS name of the location where you intend to upload the files:
<?xml version="1.0" encoding="utf-8" ?>
<customer xmlns="http://domain_name/XSchema"
xmlns:xsi="http://domain_name/XSchema"
xsi="http://domain_name/XSchema XMLFile2.xsd">
<firstname>John</firstname>
<lastname>Smith</lastname>
<joindate>2010-01</joindate>
</customer>
-
13
Upload the files to your web server and verify that the "XMLFile1.xml" document validates by either submitting through a free service such as Validome.com or by writing code to handle the validation (see Resources).
-
1
Tips & Warnings
You can create XML documents and DTDs in a variety of other development environments (e.g, Dreamweaver, Eclipse) or using a plain text editor.