Aspose.Pdf

Introduction to Schema

DTD is used to validate XML document. Although DTD defines document structure for validation, there are some limitations. Microsoft has created XML Schema with the objective of improving DTD.

 

A schema is written using XML syntax. It is therefore easier to learn and use schema as compared to DTD.

 

The dictionary defines a schema as A diagrammatic representation; an outline or a model. In the context of software, a schema is generally understood to be a model used to describe the structure of a database. It defines internal structures such as tables, fields, and the relationship between them. However, in the context of XML, as defined by the W3C, a schema is a set of rules to constrain the structure and articulate the information set of XML documents. A schema describes a model for a whole class of documents. The model describes the way in which the data is marked up, and also specifies the possible arrangement of tags and text in a valid document. A schema might be considered a common vocabulary that is needed to exchange documents between different organizations.

 

Comparing DTD with Schema

 

XML inherited the concept of DTD from SGML. While DTD is used to define content model, the valid order and nesting of elements, and to a limited extent, the data types of the attributes, they have their own limitations. Some of these are outlined below:

 

DTD uses Non-XML syntax

 

DTD is written using formal EBNF (Extended Backus-Naur Form) notation, and therefore is difficult to write and use.

 

DTD is not Extensible

 

DTD is not extensible. For example, if we have an Address DTD to catalog friends, and we want to add a new section to the code for official contacts, we will have to rewrite the entire DTD.

 

DTD has no support for Namespace

 

Namespaces can be used to introduce an element type into an XML document. However, we cannot use a Namespace to refer to an element or an entity declaration in the DTD. If a Namespace is used, then the DTD has to be modified to include any elements taken from the Namespace.

 

DTD only offers Limited Data Types

 

DTD can only express the datatype of attributes in terms of explicit enumerations and a few coarse string formats. DTD does not have a facility to describe numbers, dates, currency values, and so forth. Furthermore, DTD does not have the ability to express the datatype of character data in elements. For example, a <AGE> element can be defined to contain CDATA. However, the element cannot be constrained to just numerals when it uses a DTD.

 

Example

 

An XML file and the Schema for that XML file are given below as an example.

 

XML Document:

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<order orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="order.xsd">

<orderperson>Justin Anderson</orderperson>

<shipto>

  <name>Salman</name>

  <address>41-B Street</address>

  <city>250 Texas</city>

  <country>USA</country>

</shipto>

<item>

  <title>Aspose.Pdf</title>

  <note>Enterprise Edition</note>

  <quantity>1</quantity>

  <price>599</price>

</item>

<item>

  <title>Aspose.Pdf.Kit</title>

  <note>Professional Edition</note>

  <quantity>1</quantity>

  <price>399</price>

</item>

</order>

 

Schema (order.xsd) for the above XML Document:

 

<?xml version="1.0" encoding="ISO-8859-1" ?>

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

<xs:element name="order">

<xs:complexType>

  <xs:sequence>

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

   <xs:element name="shipto">

    <xs:complexType>

     <xs:sequence>

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

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

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

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

     </xs:sequence>

    </xs:complexType>

   </xs:element>

   <xs:element name="item" maxOccurs="unbounded">

    <xs:complexType>

     <xs:sequence>

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

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

      <xs:element name="quantity" type="xs:positiveInteger"/>

      <xs:element name="price" type="xs:decimal"/>

     </xs:sequence>

    </xs:complexType>

   </xs:element>

  </xs:sequence>

  <xs:attribute name="orderid" type="xs:string" use="required"/>

</xs:complexType>

</xs:element>

</xs:schema>

 

XML Schema Document (XSD) and Aspose.Pdf

 

The Document Object Model (DOM) of the Aspose.Pdf is created using XML Schema Document (XSD) which can be found here: Aspose.Pdf.Xsd . This schema can be used to know the detailed information of all the elements and attributes that are supported by Aspose.Pdf.

 

Create XML in VS.NET using Aspose.Pdf Schema

 

Please follow these steps to create XML files in Visual Studio.NET using Aspose.Pdf Schema ( Aspose.Pdf.Xsd ):

 

 

Schema View in VS.NET

 

 

Schema Help in VS.NET