Web Technology - Old Questions

7.  What are the advantages of using XML? Explain the rules for writing XML.

5 marks | Asked in 2074

Advantages of using 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: XML documents can be stored without [schemas] because they contain meta data; any XML tag can possess an unlimited number of attributes such as author or version.
  • Contains machine-readable context information: Tags, attributes and element structure provide context information ... opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.
  • Separates content from presentation: XML tags describe meaning not presentation. The look and feel of an XML document can be controlled by XSL stylesheets, allowing the look of a document (or of a complete Web site) to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.
  • Supports multilingual documents and Unicode: This is important for the internationalization of applications.
  • Facilitates the comparison and aggregation of data: The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.
  • Can embed multiple data types: XML documents can contain any possible data type — from multimedia data (image, sound, video) to active components (Java applets, ActiveX).
  • Can embed existing data: Mapping existing data structures like file systems or relational databases to XML is simple....
  • 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.

Rules for writing XML

1. All XML Elements Must Have a Closing Tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

    E.g. Correct: <p>This is a paragraph.</p>

           Incorrect: <p>This is a paragraph.

2. 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:

   E.g. Incorrect: <Message>This is incorrect</message>   

       Correct: <message>This is correct</message>    

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

    E.g. Incorrect: <b><i>This text is bold and italic</b></i>

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

4. 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>

5. XML Attribute Values Must be Quoted.

<note date="06/01/2012">

    <to>Tulsi</to>

    <from>Giri</from>

</note>

6. Comments in XML.

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

    <!-- This is a comment -->

7. White-space is preserved in XML. 

8. Avoid HTML tags.