XML Schema


R4R provide basic XMLSchema Tutorials concept with XMLSchema Examples .Through R4R you can develop XMLSchema programming concept. R4R provide XMLSchema Interview Questions with answers.R4R provide XMLSchema Languages study materials in easy way.

Introduction of XMLSchema

XML Schema is an XML schema language recommended by W3C (World Wide Web Consortium) in 2001.An XML schema represents the interrelationship between the attributes and elements of an XML object (for example, a document or a portion of a document). An XML schema is a set of rules to which an XML document must conform in order to be considered 'valid' according to that schema.

To create a schema for a document, you analyze its structure, defining each structural element as you encounter it. For example, within a schema for a document describing a Web site, you would define a Web site element, a Web page element, and other elements that describe possible content divisions within any page on that site. Just as in XML and HTML, elements are defined within a set of tags.

History of XMLSchema

XML Schema 1.0 specifications is divided into 3 parts and available at W3C web site

  • XML Schema Part 0: Primer - It is Provide very easy readable description of XML Schema and a quick tutorial on how to write XML schema documents using XML Schema.
  • XML Schema Part 1: Structures - A set of rules specifying the XML Schema definition language, which offers facilities for Implementation the structure and constraining the contents of XML 1.0 documents.
  • XML Schema Part 2: Data types - A set of rules specifying data types to be used in XML Schema.
  • Features of XML Schema 1.0
    1. XML Schema 1.0 is designed to validate XML 1.0 documents.
    2. XML Schema 1.0 is an XML based language. XSD documents are XML documents.
    3. XML Schema 1.0 supports data types.
    The Purpose of XML Schema

    XML Schema is an XML-based language. it is used to XML-based languages and create data models. An XML schema Discribe element and attribute names for a class of XML documents. The schema also specifies the structure that those documents must adhere to and the type of content that each element can hold.

    XML documents that attempt to adhere to an XML schema are said to be instances of that schema. If they correctly adhere to the schema, then they are valid instances. This is not the same as being well formed. A well-formed XML document follows all the syntax rules of XML, but it does necessarily adhere to any particular schema. So, an XML document can be well formed without being valid, but it cannot be valid unless it is well formed.

    Schema describes the structure of an XML instance document

    An XML schema define the structure or model of an XML instance document by defining what each element must or may contain. An element is limited by its type. For example, an element of complex type can contain child elements and attributes, whereas a simple-type element can only contain text. This diagram below gives a first look at the types of XML Schema elements

    The following is a high-level overview of Schema types
    1. In The Structure Of Xml Schema Elements can be of simple type or complex type.
    2. Simple type elements can only contain text. They can not have child elements or attributes.
    3. All the built-in types are simple types (e.g, xs:string).
    4. Schema authors can derive simple types by restricting another simple type. For example, an email type could be derived by limiting a string to a specific pattern.
    5. Simple types can be atomic (e.g, strings and integers) or non-atomic (e.g, lists).
    6. Complex-type elements can contain child elements and attributes as well as text.
    7. By default, complex-type elements have complex content, meaning that they have child elements.
    8. Complex-type elements can be limited to having simple content, meaning they only contain text. They are different from simple type elements in that they have attributes.
    9. Complex types can be limited to having no content, meaning they are empty, but they have may have attributes.
    10. Complex types may have mixed content - a combination of text and child elements
    Advantage of XMLSchema
    1. XML Schema provides a powerful mechanism for specifying datatypes for XML elements and attributes.
    2. Integration & Accessibility.
    3. XML Schema’s support for namespaces enables XML documents to contain unique identifiers, and therefore incorporate more than one commonly used vocabulary at a time.
    Difference Between XMLSchema and DTD (Document Type Definition)
    XML Schema is namespace aware while DTD is not
    XML Schemas are written in XMLwhile DTDs are not
    XML Schema is strongly typedwhile DTD is not
    XML Schema has a wealth of derived and built-in data types that are not available in DTD.
    XML Schema does not allow inline definitions while DTD does
    XMLSchema Tutorials
    XMLSchema Examples
    XMLSchema Interview Materials