Basics of XML and Validation of XML

Basic Concept of XML

In this series I am trying to explain what XML is, why we need this and also how it works. I deeply appreciate the CodeProject article; without CodeProject I could not create this article. I have divided the XML material into the three parts advantages, disadvantages and more information.

  1. Basic concepts of XML
  2. Validate your XML code on the client side (JavaScript)
  3. Get a XML data and show the front end using jQuery
  4. Get the SQL Server data using XML and JavaScript

Concept of XML
Introduction


The Extensible Markup Language (XML) is a general-purpose markup language. It is classified as an extensible language because it allows users to define their own tags as in the following:

<your keyword> //Root Tag Start here
</your keyword>. //Root Tag End Here.

In Software Engineering, extensible refers to the system that can be modified by changing or adding features. Its primary purpose is to facilitate the sharing of data across various information systems, particularly via the internet.

XML is a recommendation of the World Wide Web Consortium (W3C). It is a fee-free open standard. The W3C recommendation specifies both the lexical grammar of and the requirements for parsing XML.

The basic difference between HTML and XML is:
  1. HTML was designed to display data and to focus on how data looks
  2. XML is designed to describe data and to focus on what data is

We have many reasons for why to use XML. I am trying to explore why we need the language.

need of XML

Figure 1.1: How to send a Request SQL Server and get a data in XML format.

Simplicity: XML is easy to understand. You can create tags, here I am trying to create a Book Order.

Check this type:

<book>

  <orderNumber>

    <BookName>

    </BookName>

  </orderNumber>

</book> 

You are free to develop it as you wish or want.

Standardization: XML is an international standard. This means that anyone in the world is likely to have the ability to view your document.

Different Applications: You can make one data page and use it over and over again. This means that if you are cataloging inventory then you only do it once. You can create as many display pages as you want for that data. XML allows you to generate various styles and formats based on one page of information.

Understandable: XML formats value in an easy to understand format. XML has no predefined tags, like that Int32, String or anything else.

Accessibility:
With XML you compartmentalize your work. Separating data makes it accessible when changes are needed.


XML Validation

There are two levels of correctness of an XML document:

  1. XML with correct syntax is Well Formed XML
  2. XML validated against a DTD is Valid XML

A Well Formed XML document is a document that conforms to the XML syntax rules like:

  1. XML documents must have a root element
  2. XML elements must have a closing tag
  3. XML tags are case sensitive
  4. XML elements must be properly nested
  5. XML attribute values must always be quoted

A Valid XML document is a Well Formed XML document, that conforms to the rules of a Document Type Definition (DTD).

The following are examples of XML that is not Well Formed according to XML DTD.

XML DTD
Missing one tag:

<!—-Missing Tag here like -->

<BookList >

  <!—Root Eelement -- >

  <Book>

    <Title>

      Java Programming is one of the best in the IT line

    </Title>

    <Publisher>

      Willy India Title is Missing Here

    </Publisher>

  </BookList>

<!--Root element end here-->

<Book category=".net">

  <!--Error is here-->

  <Title>Java Complete Reference</Title>

  <!--well format and error find-->

  <Publisher>Not mention</Publisher>

</Book>

<?xml version="1.0" encoding="utf-8"?>

<!--Reference of XML version-->

<!--Meaning of above Line version="1.0" means that this is the XML standard this file conforms to

encoding="utf-8" means that the file is encoded using the UTF-8 Unicode encoding-->

<!-- no Pre defined keywords Here-->

<BookList>

  <!--Root Eelement-->

  <!--Root Eelement start here-->

  <Book>

    <!--sub Root here-->

    <Title>jQuery: Novice to Ninja</Title>

    <Publisher>Site point</Publisher>

  </Book>

  <!--Sub Root Eelement Here -->

  <Book>

    <!--Again sub Root here-->

    <Title>Learning jQuery</Title>

    <Publisher>PACKT</Publisher>

  </Book>

  <Book>

    <!--another sub Root start here-->

    <Title>Head First jQuery</Title>

    <!--well format and error find-->

    <Publisher>O'Reilly</Publisher>

  </Book>

  <Book category="C# Language">

    <Title>C# Complete Reference</Title>

    <!--well format and error find-->

    <Publisher>Not mention</Publisher>

  </Book>

  <Book category="Java Language">

    <Title>Java Complete Reference</Title>

    <!--well format and error find-->

    <Publisher>Not mention</Publisher>

  </Book>

  <!-- Can't do this type.-->

  <!--No well format Title Tag is Missing-->

  <!--<Book>

<Title>

<Publisher>

Willy India

</Publisher>

</Book>-->

  <!--Case Sensitive-->

  <!--<Book category="Java Language">

<Title>Java Complete Reference</Title>

-->

  <!--well format and error find-->

  <!--

<Publisher>Not mention</Publisher>

</BOOK>-->

  <!--attribute values must always be quoted -->

  <!--Can't do this type-->

  <!--<Book category=.net> -->

  <!--Error is here-->

  <!--

<Title>Java Complete Reference</Title>

-->

  <!--well format and error find-->

  <!--

<Publisher>Not mention</Publisher>

</Book>-->

</BookList>

<!--Root element end here-->  

Advantage: Simple

There is no predefined keywords.

Communication by various types of applications.

Reference: w3schools


Similar Articles