How to Use XSD and XML
Extensible Markup Language (XML) provides websites with a standard, formatted list of data. The XML schema file is referred to as "XSD" or "XML Schema." The XML schema file lays out the data structure, so the web engine knows how to parse and format the data within the XML file. Both of these file structures work together to format the data you present to readers on a web page. You create these files together and add a reference to the XML file in your XSD schema to associate the two.
Instructions
-
-
1
Create your XML file. In this example, a simple list of customers is shown. The following code creates an XML file with one customer listed:
<customer>
<firstname>Joe</firstname>
<lastname>Smith</lastname>
</customer>
-
2
Create your XSD file. The XSD file defines each field in the XML file. In this instance, there are two fields: first name and last name. This is a sample XSD file that defines a list of customers:
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
-
3
Associate the XSD file to the XML file. This is accomplished using the "element" tag. Add the following code to the top of your XSD file:
<xs:element name="customer">
Notice that the "name" property is given the same value as the XML file's list of records, which in this case is "customer." This associates the two files, so you can use them together in your web pages.
-
1
References
- Photo Credit computer image by blaine stiger from Fotolia.com