How to Understand XSD

How to Understand XSD thumbnail
An XSD defines the structures that can occur in an XML tree.

An XSD is an XML Schema Definition, a set of rules describing the structure of XML markup. XSDs are used to define the structures that one or more XML documents must conform to. Because XML is customizable and adaptable to different uses, XSDs are a way for developers to create a set structure that they want to use within their XML data. XSDs reflect the nature of a set of data in a similar way to a Relational Database design. An XSD defines the various data elements that can be included in the relevant XML, and indicates the data-types and relationships within these elements.

Instructions

    • 1

      Look at sample XSDs to familiarize yourself with the syntax. The best way to gain an understanding of how XSDs work is to look at some real examples, together with examples of XML conforming to them. XSDs are also written in XML, and must comprise a well-formed tree structure. An XSD typically contains a list of the elements that are allowed in the XML; the attributes that these elements can have; the elements that are child elements of others; the number of child elements that can occur; the order of child elements; the data types and values for both elements and attributes.

    • 2

      Learn how XSDs represent elements. In the following example, the XSD specifies an element named "picture," which should consist of a text string:

      <xs:element name="picture" type="xs:string"/>

      An actual XML element reflecting this could be:

      <picture>imagename.jpg</picture>

      Here the picture element is given a default value:

      <xs:element name="picture" type="xs:string" default="imagename.jpg"/>

    • 3

      Learn how element attributes are represented within XSDs. Attributes are used where you have additional information about a data element that does not comprise a data element in itself. In this example, an attribute with the name "width" is specified as being an integer and required in all cases:

      <xs:attribute name="width" type="xs:integer" use="required"/>

      An example in XML would be:

      <picture width="300">imagename.jpg</picture>

      Note that although the attribute type is an integer, it must still be listed between quotation marks.

    • 4

      Learn how Complex Types are reflected in XSDs. Complex Types are mostly elements that can contain child elements. In this example, the "picture" element is defined as a child of another element named "gallery" along with a further element named "title," which is also a text string:

      <xs:element name="gallery">

      <xs:complexType>

      <xs:sequence>

      <xs:element name="title" type="xs:string"/>

      <xs:element name="picture" type="xs:string" default="imagename.jpg"/>

      </xs:sequence>

      </xs:complexType>

      </xs:element>

      Sample XML reflecting this structure could be as follows:

      <gallery>

      <title>Lovely Pictures</title>

      <picture width="300">picture1.jpg</picture>

      <picture width="250">picture2.jpg</picture>

      </gallery>

    • 5

      Learn how XSDs indicate the number of times that an element can occur. In this excerpt, the "picture" element is specified as being able to occur any number of times:

      <xs:element name="picture" type="xs:string" default="imagename.jpg" maxOccurs="unbounded"/>

      This example states that the "title" element is optional as the minimum number of occurrences is set to zero:

      <xs:element name="title" type="xs:string" minOccurs="0"/>

Tips & Warnings

  • If your XSD is long and complex, it helps to split it into sections and use comments to make it a little more readable.

  • Often, XSDs are generated from XML, but you should always use your XSDs to validate that your XML documents are correctly structured.

Related Searches:

References

Resources

  • Photo Credit Jason Reed/Photodisc/Getty Images

Comments

You May Also Like

  • How to Make XSD

    The W3C, or World Wide Web Consortium, has recommended the XML Schema language (XSD) as a replacement to the older Document Type...

  • How to Comprehend Reading

    Comments. You May Also Like. How to Comprehend What You Are Reading. Reading comprehension (understanding what you are reading) can be difficult...

  • XSD Validation Rules

    XSD Validation Rules. An XSD, or XML Schema Definition, is an XML document that describes some other XML data. The main purpose...

  • How to Compile XSD

    XSD is a compiler application included with Microsoft Visual Studio. The software compiles and creates a schema from your website's Extensible Markup...

  • How to Link XSD to XML

    XML Schemas are a way of defining the structure that one or more XML documents should conform to. Just as with HTML...

  • How to Generate an XSD

    XSD files are Extensible Markup Language (XML) schema files that are alternatives to DTD files. XSD files are used to define the...

  • How to Open XSD Files

    An XSD (XML Schema Definition) file shows the relationship between the different elements in an XML (Extensive Markup Language) file. XML files...

  • How to Import an XSD File

    If most of the schema information you need is already contained within another XSD file, there is no reason to duplicate all...

  • XSD to XML Conversion

    XML (eXtensible Markup Language) is a standardized method of describing data and the relationships between data. XML is used to simplify the...

  • How to Explain Database Handling With the XML Schema

    Extensible Markup Language (XML) was developed by the World Wide Web Consortium (W3C) to create and maintain data in a structured format...

  • Example of the XSD File

    The file extension .xml is a text file that is commonly seen within XML schema. These files allow programmers and Web developers...

  • How to Convert PSD to JPG

    Let's say you have a PSD (Photoshop) file that you would like to use, but the program you are working with specifies...

  • Easy Way to Learn Formulas in Excel

    Microsoft Excel, the most widely used spreadsheet program in the world, features hundreds of powerful functions. Many of the mathematical functions included...

  • How to Open a .Xsd File in Adobe Acrobat Reader

    An XSD computer file is a text-based file that contains instructions for the XML file it is associated with. Typically an XSD...

Related Ads

Featured