Web Technologies - Old Questions

3.  Discuss the benefits of using XML. Differentiate XML schema with DTD. Write an XML DTD to describe “person” as an element and “Name, address, phone-no, and Age” as its attributes.

10 marks | Asked in 2071

XML (Extensible Markup Language) is  a markup language that defines a set of rules for encoding documents in a format that is both human readable and machine readable. XML is designed to store and transport data.

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

Difference between XML schema and DTD

  • XML schemas are written in XML while DTD are derived from SGML syntax.
  • XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes.
  • XML schemas allow support for namespaces while DTD does not.
  • XML schemas define number and order of child elements, while DTD does not.
  • XML schemas can be manipulated on your own with XML DOM but it is not possible in case of DTD.
  • using XML schema user need not to learn a new language but working with DTD is difficult for a user.
  • XML schema provides secure data communication i.e. sender can describe the data in a way that receiver will understand, but in case of DTD data can be misunderstood by the receiver.
  • XML schemas are extensible while DTD is not extensible.

XML DTD to describe given element and attributes

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

<!DOCTYPE person

[

<!ELEMENT person EMPTY>

<!ATTLIST person Name CDATA #REQUIRED >

<!ATTLIST person address CDATA #REQUIRED >

<!ATTLIST person phone-no CDATA #REQUIRED >

<!ATTLIST person Age CDATA #REQUIRED >

]>

<person Name="Jayanta" address="Ramechhap" phone-no="9843000000" Age="20"></person>