Schema In XML

Introduction of Schema -: This is define a set of rules for xml documents. It is more powerful than DTD(Document Type Definition). DTD can be included within an XML file or they can be external. Schema are always external files. An XML Schema describes the structure of an XML document.

These are written in xml so existing xml tools can be used to determine whether a schema is valid. These support data types, so we can be sure that data types in our xml file are handled properly. Schema are extensible, so they can handle future enhancements gracefully.

If schema are so great, why do we need DTD? Great question! As a casual xml user you may not need a schema to define the rules for our xml file. A simple internal DTD may be sufficient. These are best alternative of DTD.

Schema are just another XML document, but they are written using a specific namespace. This language is also referred to as XML Schema Definition . For using in your XML file it must be declare in your elements as like

<xs:elememts name="netnic" type="website"/>

According the definition type it has three type-:

simple type -: Simple type element is used only in the context of the text. Some of the predefined simple types are available schema in xml these are: xs:integer, xs:boolean, xs:string, xs:date.

Complex type -: A complex type is a container for other element definitions. This allows us to specify which child elements an element can contain and to provide some structure within our XML documents.

Global Type-: We can define a single type in our document, which can be used by all other references. For example, suppose we want to generalize the person and company for different addresses of the company.

Example -:

<xs:element name="Netnic"> //defines the element

<xs:complexType>  //element is a complex type
    <xs:sequence>//sequence of elements
         <xs:element name="To" type="xs:string"/> // string type text
          <xs:element name="From" type="xs:string"/>//string type text
          <xs:element name="Subject" type="xs:string"/> //string type text
          <xs:element name="Message" type="xs:string"/> //string type text




XML schema data types-: Like the other programming language it support data type as like integer, decimal and string.

The XML Schema definition describes several data types. Like XML itself, data types form a hierarchy. At the root of the hierarchy is any Type, which literally means “any type.” Unless you specify otherwise, the data type for elements and attributes is assumed to be any Type.

Simple data type in xml schema -: Simple data types cannot have attributes or child elements. This works well for elements like First Name and Birthday we don’t want those elements to have children or any attributes. List of simple data type

  • Integer data type -: schema in xs:integer value 5,7,11,14, etc.
  • Decimal data type-: schema in xs:decimal example 6.27,123.43 etc.
  • String data type-: schema in xs:string example any character as like netnic,vikram,
  • Date -: schema in xs:date example 26-04-2020

Advantages of schema in xml- : The great strength about XML Schema is that they are written in XML .

  • we do not necessary to learn a new language
  • We can use XML editor to edit our Schema files because schema are written in xml programming language.
  • we can use your XML parser to parse our Schema files
  • Schema will be transfer with XSLT.
  • we can manipulate our Schema with the XML DOM

Feature of XML Schema -: There are many feature of xml schema. These are the

  • Richer datatypes. Schema defines boolean, numbers, dates and times, URIs, integers, decimal numbers, real numbers, intervals of time, etc.
  • predefined types, there will be facilities for creating other types and aggregate types
  • User defined types, called Archetypes in the draft. An archetype allows you to define your own named datatype. For example, you might define a “PostalAddress” datatype and then define two elements, “ShippingAddress” and “BillingAddress” to be of that type.
  • This is a more powerful than simply defining the two elements to have the same structure because the shared archetype information is available to the processor.
  • Attribute grouping. It’s not uncommon to have several attributes that “go together”. For example, common attributes that apply to all elements or several attributes that augment graphic or table elements. Attribute grouping allows the schema author to make this relationship explicit. In DTD, the grouping can be achieved with a parameter entity, simplifying the process of authoring a DTD, but the information is not passed on to the processor.
  • Refinable archetypes, or “inheritance”. This is probably the most significant new feature

More Read about XML

Leave a Comment