XML Tutorial for Beginners Study Material Notes with Examples

 XML Tutorial for Beginners Study Material Notes with Examples

XML

XML  stands for Extensible Markup Language. XML is designed to transport  and store  data but HTML is designed to display data.

XML tags are not predefined. You must define your own tags.

e.g. ,

<?Xml version = ” 1.0 “

encoding = ” ISO-8859-1’’ ?>

<note>

<to>Tove</to>

<from  Jani </from>

<heading>Remi nderg</heading>

<body>Do not forget me this weekend ! <body>

</note>

The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1=Latin-invest European character set).

The next line describes the root element of the document (like saying: “this document is a note”) The next 4 lines describe 4 child elements of the root (to, from, heading and body) and finally the last line defines the end of the root element.

Key Points

  • XML is used in many aspects of web development, often to simplify data storage and sharing.
  • XML simplifies data sharing because in the real world, computer systems and databases contain data in incompatible formats.
  • XML documents from a tree structure that starts at “the root” and branches to “the leaves”.
XML Tutorial for Beginners Study Material Notes with Examples
XML Tutorial for Beginners Study Material Notes with Examples

Applications of XML

  • Refined Search Results With XML specific tags, search engines can give users more refined search results. A search seeks the term in the tags, rather than the entire documents.
  • EDI Transactions XML allows data to be exchanged, regardless of the; computing system.
  • File Converters Many applications have boon written to convert existing document into the XML standards.

XML Syntax Rules

< ? XML version = “1.0” encoding = “IS08859-1″?› <Student>

<Name> RAM < /Name >

<Roll No> 04</Roll No>

</Student>

  • XML Declaration The XML page is declared as < ? XML version = “1.0” encoding = “ISO – 8859 – 1”?>. The declaration must be included in XML It defines the XML version and the character encoding used in the documents.
  • Root Element The XML root element is defined as a tag in which all the other tags are included in our example <student> is root tag.

Syntax rules of XML page are given below

  • All XML elements must have a closing tag.
  • XML tags are case sensitive.
  • XML tags must be properly nested.
  • XML documents must have a root element.
  • Always quote the XML attribute values.

XML Schema

XML schema is a definition language for describing the structure of XML document.

Elements of XML Schema

  • <XS : element> It is used to define elements.
  • <XS : attribute> It is used to define individual attribute.
  • <XS : simple type> Marks the beginning of type that has no attributes and only text contents.
  • <XS : choice> Describes the set of sub-elements an element can contain
  • <XS sequence> Describes the set of sub-elements in a particular order.

valid XML Document

XML document is said to be valid, if it has a Document Type Definition (DTD) or XML schema associated with it and if the document complies with it.

Well Formed XML Document

XML document with correct syntax is called well formed XML document.

DTD (Document Type Definition)

A document type definition defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes. A DTD can be defined inside a XML .document or an external reference can be declared.

  • Internal DTD If the DTD is defined inside the XML document, it should be wrapped in a DOCTYPE definition with the following syntax.

< ! DOCTYPE root element [element declarations] >

  • External DTD If the DTD is defined in an external file, it should be wrapped in a DOCTYPE definition with the following ‘syntax’:

< !DOCTYPE root element system “filename” >

Importance of DTD

  1. With a DTD, an XML file carries a description of its own format.
  2. With a DTD, Independent groups of people can agree to use a standard DTD for interchanging data.
  3. DTD can be used to verify data.

XML Parser

To use XML document in an application, we need to parse it. An XML Parser road an XML document and separates it into start tags, attributes and end tags.

 Two  types  of  XML  parser  are

  1.  DOM (Document Object Model)        2. SAX (Simple API for XML) DOM 

DOM(Document Object Model)

The DOM parser presents an XML document as a tree structure with the elements, attributes mid text defined as nodes. The DOM provides an XML document into a collection of objects in an object model in a tree structure.

  • Benefits of using DOM DOM makes easier to modify data, to rem It  or to insert new one.
  • Advantages of using DOM DOM is very useful when a document is small,
  • Application DOM model is useful for interactive applications.

SAX (Simple API for XML)

SAX works in serial access modes to parse XML documents. SAX is also called as an event driven protocol because it implements the technique to register the handler to invoke the callback methods whenever an event is generated.

Key Points                                                                                           

  • SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by the DOM.
  • Where the DOM operates on the document as a whole, SAX parser operate on each piece of the XML document sequentially.
  • DOM provides access to the information stored in our XML documents as a hierarchical object model.

Sample XML Document

< ? XML Version = “1.0”?>

<Book>

<Book Name> WebTech</BookName> <Author>

<Author 1> RAM</Author 1>

<Author 2>Shyam</Author 2> </Author>

<Publisher> Arihant</Publisher> <Price>! 500</Price>

</Book>

SAX Approach for the Sample XML Document

  • Start Element Book
  • Start Element BookName
  • End Element BookName
  • Start Element Author
  • Start Element Author 1
  • End Element Author 1
  • Start Element Author 2
  • End Element Author 2
  • End Element Author
  • Start Element Publisher
  • End Element Publisher
  • Start Element Price
  • End Element Price
  • End Element Book

____

DOM Approach for the Sample Document XML

XML Tutorial for Beginners Study Material Notes with Examples
XML Tutorial for Beginners Study Material Notes with Examples

Sorting in Design and Analysis of Algorithm Study Notes with Example

Learn Sorting in Handbook Series:  Click here 

Follow Us on Social Platforms to get Updated : twiter,  facebookGoogle Plus

Leave a Reply

Your email address will not be published. Required fields are marked *