XML Introduction in VB.NET

In this article we will learn about the XML.
  • 2760

In this article we will learn about the XML.

XML (EXtensible Markup Language)

  1. XML stands for EXtensible Markup Language.
  2. XML is a markup language much like HTML.
  3. XML was designed to carry data, not to display data.
  4. XML tags are not predefined. You must define your own tags.
  5. XML is designed to be self-descriptive.
  6. XML is a W3C Recommendation.
     

XML Benifits - These are the following benifits of XML. 

Simplicity

Information coded in XML is easy to read and understand, plus it can be processed easily by computers.

Openness

XML is a W3C standard, endorsed by software industry market leaders.

Extensibility

There is no fixed set of tags. New tags can be created as they are needed.

Self-description

In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes.

Contains machine-readable context information

Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.
This is a major advantage over HTML or plain text, where context information is difficult or impossible to evaluate.

Facilitates the comparison and aggregation of data

The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.

Provides a 'one-server view' for distributed data

XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data - the World Wide Web can be seen as one huge XML database.

XML Syntax Rules

All XML Elements Must Have a Closing Tag

In HTML, elements do not have to have a closing tag:

<p>This is a paragraph.
<p>This is another paragraph.

In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

<p>This is a paragraph</p>
<p>This is another paragraph</p>

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.

Opening and closing tags must be written with the same case:

<Message>This is incorrect</message>
<message>This is correct</message>

XML Elements Must be Properly Nested

In HTML, you might see improperly nested elements:

<b><i>This text is bold and italic</b></i>

In XML, all elements must be properly nested within each other.

<b><i>This text is bold and italic</i></b>

In the example above, "Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element.

XML Documents Must Have a Root Element

XML documents must contain one element that is the parent of all other elements. This element is called the root element.

<root>
<child>
<subchild>.....</subchild>
</child>
</root>

XML Attribute Values Must be Quoted

Study the two XML documents below. The first one is incorrect, the second is correct:

<note date=12/11/2007>
<to>Tove</to>
<from>Jani</from>
</note>

<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>

The error in the first document is that the date attribute in the note element is not quoted.

Some characters have a special meaning in XML.

Entity references

There are 5 predefined entity references in XML:

&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark

Comments in XML

The syntax for writing comments in XML is similar to that of HTML.

<!-- This is a comment -->

White-space is Preserved in XML

HTML truncates multiple white-space characters to one single white-space:
HTML: Hello Tove
Output: Hello Tove
With XML, the white-space in a document is not truncated.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.