Home arrow XML arrow Page 4 - XML Basics

XML Basics

When I first heard about XML, I thought it was something similar to HTML. Needless to say, I was wrong. XML and HTML were designed with different goals. XML was designed to describe data and HTML was designed to display data. In this article we will try to learn some basics about XML. Then we will learn about DTD and XML schemas.

Author Info:
By: Mamun Zaman
Rating: 4 stars4 stars4 stars4 stars4 stars / 43
September 05, 2007
  1. · XML Basics
  2. · XML Tags and Conventions
  3. · More on Elements
  4. · XML Schema

print this article

XML Basics - XML Schema
(Page 4 of 4 )

XML Schema is an XML-based alternative to DTD. An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD). An XML Schema defines the following:

  • Elements and attributes that can appear in a document.
  • Child elements.
  • The order and number of child elements.
  • Whether an element is empty or can include text.
  • Data types for elements and attributes.
  • Default and fixed values for elements and attributes.

The schema element is the first element in an XML schema file. The prefix xsd: is used to indicate the XML schema namespace:

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

The main sub-elements in an XML schema document are:

  1. element – declares an element.
  2. attribute – declares an attribute.
  3. complexType – defines elements that can contain other elements and attributes.
  4. simpleType – defines elements that can not contain other elements or attributes. These elements are of basic types, including string, date, integer etc.

The xsd:annotation and xsd:documentation tags are used for providing a description of the document. Here is an example:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:documentation xml:lang="en">
            Bookstore schema for book.xml


In our XML example the element bookstore is a complexType element because it contains book sub-elements.

<xsd:element name="bookstore" type="bookstoreinfo"/>

<xsd:complexType name="bookstoreinfo">
            <xsd:element name="book" type="bookinfo"/>

Our book element is also a complexType element.

<xsd:compleType name="bookinfo">
            <xsd:element name="title" type="titleinfo">
            <xsd:element name="author" type="xsd:string"/>
            <xsd:element name="year" type=" xsd:string"/>
            <xsd:element name="price" type=" xsd:string"/>

The sub-elements author, year and price are of type xsd:string. The sub-element title is of complexType because it has an attribute named id. To define an attribute use the following: 

<xsd:attribute name="id" type="xsd:string" use="required"/>

Use value required means this attribute is mandatory. By default attributes are optional.

Since XSD uses XML it is also extensible, and does not require learning a new language.

To manipulate an XML document, we need an XML parser. The parser loads the document into a computer's memory and can be manipulated using the DOM. The DOM treats the XML document as a tree.

XML is basically about defining data. XML is also used for storing data and sharing data between applications. With XML you can define documents that are understood by different software and applications. But to make these documents understandable to humans, your need to represent them. You can represent XML data using Cascading Style Sheets. But XSL is the preferred solution for converting XML documents into HTML. It can be used on the client side but the best solution is to use XSL on the server side and make it visible to any browser.

XML usage increases every day. With XML, financial information can be exchanged over the Internet easily. We should expect to see a lot about XML and B2B (Business To Business) in the near future. XML is going to be the main language for exchanging financial information between businesses over the Internet. So why wait? Let’s learn more about XML and start using it today!

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials