https://www.techtarget.com/whatis/definition/XSD-XML-Schema-Definition
XML Schema Definition or XSD is a recommendation by the World Wide Web Consortium (W3C) to describe and validate the structure and content of an XML document. It is primarily used to define the elements, attributes and data types the document can contain. The information in the XSD is used to verify if each element, attribute or data type in the document matches its description.
An XSD is similar to earlier XML schema languages, such as Document Type Definition (DTD), but it is a more powerful alternative as it provides greater control over the XML structure.
In general, a schema is an abstract representation of an object's characteristics and relationship to other objects in a document. An XML schema represents the relationships between the attributes and elements of an XML object.
The process of creating a schema involves analyzing the document's structure and defining each structural element encountered. For example, a schema for a document describing a website would define a website element, a webpage element and other elements that describe possible content divisions within any page on that site. These elements are defined within a set of tags in HTML and also in XML.
As the language of the XML schema, XSD is similar to a database schema that describes the data within a database. It defines the building blocks of an XML document, including:
There are hundreds of standardized XML formats that are used globally. Most of these XML standards can be defined and understood with XML schemas.
The key benefits of XML schemas, and therefore of XSD, are as follows:
In addition, XSD makes it easy to reuse schema in other schema, reference multiple schemas in the same document and create new data types derived from standard data types.
An element is the building block of an XML document and is defined within the XSD. The three types of XSD schema elements can be defined as:
The choice depends on whether the element is a parent element or a leaf element. An element can be defined in the XSD as <xs:element name = "x" type = "y"/>.
The simpleType element contains only text and cannot have attributes. Examples include:
For example: Syntax: <xs:element name = "phone_number" type = "xs:int" />
However, a complexType can contain text, elements and attributes. It can be a parent to all the elements and attributes within it. Further, it provides structure within XML documents and allows building a simple element hierarchy in a document.
With a globalType element, a single type can be defined in the XML document, which can then be used by all other references. It simplifies document maintenance.
Elements declared as the direct child of an XML schema are considered global elements and can be used throughout the schema. However, elements declared within a complexType cannot be used elsewhere in the schema because they are considered local elements.
XSD attributes provide additional information within an element. They have two properties: name and type. The syntax is written as <xs:attribute name = "x" type = "y"/>.
Unlike XSD elements, an XSD attribute is always of the simpleType. It can have a fixed value or a default value. Further, an attribute group, which defines an association between a name and a set of attribute declaration, can be reused in complexType definitions.
In XSD, a nillable attribute of an element can be declared as true to represent a null value being sent to or from a relational database with an element.
In creating a new simple or complex data type, an XSD type definition is used. The data type can be either named or anonymous. While a named data type is always defined globally, the anonymous type does not have a name and thus cannot be referenced. A base type definition is used as a base to create new definitions.
XSD content models are used to define the order of elements in a group in an XSD.
XSD offers several advantages over DTD. For one, XSD is written in XML so that it doesn't require intermediary processing by a parser. Because DTD is not written in XML, it requires the help of parsers. This means separate parsers are needed for XML and DTD.
XSD also offers self-documentation, automatic schema creation and the ability to be queried through XSLT.
Other advantages of XSD over DTD are:
Of course, there are some challenges and limitations of XSD as well. It can be unnecessarily complex, and it lacks a formal mathematical description. It also provides limited support for unordered content.
See also: AJAX, SPML, BPEL , XACML , ebXML, Information and Content Exchange
09 May 2022