XML Document Modeling

As you know already that XML is extensible markup language that help display information, store information in meaningful format, and transport information for applications and humans.

Advertisements

When we talk about documents, then first thing come to our mind is articles, books that are organized in chapters, sections, paragraphs, etc. That is only in the traditional sense.

In XML document, a wide variety of information can be stored and transported; therefore, XML document has wider definition than the traditional documents. One special feature of XML is the ability to exchange data between applications.

In simple words, XML document does nothing but hold information to display or exchange or transport.

XML Document Tree

The XML document that is a piece of information is arranged order of elements. Basically, elements are arranged to create a document tree structure. At the top, you have the root element, or a single element called the document element, and all other elements are nested within the root element. As you know from previous lessons, that elements are simply labeling the content of the document.

Consider the following information written in XML.

<?xml version="1.0"?>
<student> 
  <name>
     <firstname>Radhe</firstname>
     <lastname>Govind</lastname> 
 </name>   
  <age>23</age>
  <courses>
    <subject1> Computer Science</subject1>
    <subject2> Mathematics </subject2>
  </courses>
  <grade>A+</grade>
</student>

The above XML document has student information such as name, course, age and grade. The name and course are asking for more information such as first name and last name. The courses are asking for subjects that a student can study.

XML present this document as a document tree for easy access. It is also known as XML DOM (XML Document Object Modelling).

Figure 1 - XML Document Tree Structure
Figure 1 – XML Document Tree Structure

Not only text information, but XML can be used to store pictures or graphic images. The Scalable Vector Graphics (SVG) language is used to create line drawings, and since, they are vectors images, there is no problem resizing them.

Difference Between XML document or a File

The primary difference between the XML document is the structure. A file is stored in bits, and bytes. Therefore, files have different permissions and restrictions on them. The file is a physical structure stored in the computer system.

XML document is logical structure and new markup language can be created following the rules of the XML. Since, there are not restrictions on XML documents, it can be used anywhere.

Advertisements

Document Modeling

Since, XML is a markup language creator itself, how do you create a language from XML ? There are two ways to create XML documents.

  1. Freeform XML
  2. Document Type Definition (DTD)

Freeform XML

The freeform XML is used to create your own XML language tags following the rules of XML syntax. These minimum rules are:

  • XML documents contains a root element
  • XML tags are properly closed, and not omitted.
  • XML tags are case sensitive means you cannot have different case for opening or closing element.
  • XML elements must be nested properly and in right order.
  • XML attribute values must double quotes.

When a document satisfies the minimum rules of XML document, it is called a well-formed document.

But its usefulness is limited because of no restrictions, and that increases the chances of error. The application can throw lot of errors if you leave lot of mistakes in the document.

Document Type Definition (DTD)

The XML provides you with a mechanism to define the language before you use it, through document modeling. The model specifies the rules of the XML language, and any document you create and use this model must validate itself with DTD.

The document type definition is mentioned at the top of the XML document for validation check which declares the tags and data to be used within the document.

XML Schema

The newest document model is XML schema, which uses templates for XML documents to validate it. The schemas are also XML documents, and we will learn it in future lessons.

Any markup language created using the XML is called XML Application, and there are many such applications available all over the internet.

Summary

In this lesson, you have learned that XML can help us create new XML based languages using freeform XML that follows basic rules of XML documents. Since, minimum rules are prone to errors, XML offer document model such document type definition (DTD) and schema modeling.

Document modeling is mechanism to specify our own rules for XML languages and validate the documents.

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.