XML EXtensible Markup Language XML is a markup
XML - EXtensible Markup Language XML is a markup language much like HTML XML is derived from SGML – Standard Generalized Markup Language XML was designed to store and transport data XML was designed to be self-descriptive XML is a W 3 C Recommendation XML is a software- and hardware-independent tool for storing and transporting data <? xml version="1. 0" encoding="UTF-8"? > <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
<? xml version="1. 0" encoding="UTF-8"? > XML Prolog Encoding is the process of converting unicode characters into their equivalent binary representation. When the XML processor reads an XML document, it encodes the document depending on the type of encoding. Encoding Types UTF-8 UTF-16 UTF stands for UCS Transformation Format UCS stands for Universal Character Set. The number 8 or 16 refers to the number of bits used to represent a character.
Uses of XML Ø used to store and transport data (data is stored in plain text format) Ø used to define user defined tags Ø used in many aspects of web development. Ø used to separate data from presentation. Ø XML simplifies platform changes and data availability. Ø XML can be used to exchange the information between organizations and systems. Ø XML can be used for offloading and reloading of databases. Ø XML also makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. Ø XML can easily be merged with style sheets to create almost any desired output. Ø Virtually, any type of data can be expressed as an XML document. Ø With XML, data can be available to all kinds of "reading machines" like people, computers, voice machines, news feeds, etc.
Differences between XML and HTML XML was designed to carry data - with focus on what data is HTML was designed to display data - with focus on how data looks XML tags are not predefined <student> <name>AAA</name> <pin>11111</pin> </student> HTML tags are predefined <h 1> BBB </h 1> XML shows relationship between data elements but such relationship does not exist in HTML
XML Syntax Rules
XML Syntax Rules 1. 2. 3. 4. 5. 6. 7. 8. XML document can have a prolog XML document must contain a root element XML elements must have a closing tag XML elements must be properly nested Xml tags are case sensitive XML attribute values must be quoted XML elements can have entity references XML comments are similar to HTML
XML Syntax Rules 1. XML document can have a prolog <? xml version="1. 0" encoding="UTF-8"? > It is called as XML prolog or XML declaration The XML prolog is optional. If it exists, it must come first in the document. XML prolog does not have a closing tag XML prolog is not a part of XML document
XML Syntax Rules 2. XML document must contain a root element XML documents must contain one root element that is the parent of all other elements: <root> <child> <subchild>. . . </subchild> </root> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Welcome</body> </note>
XML Syntax Rules 3. XML elements must have a closing tag HTML XML <p> Hello </p> <br/>
XML Syntax Rules 4. XML elements must be properly nested HTML <b><i>This text is bold and italic</b></i> XML <b><i>This text is bold and italic</b></i> <b><i>This text is bold and italic</i></b>
XML Syntax Rules 5. 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> Hello </message> <message> Hello </message>
XML Syntax Rules 6. XML attribute values must be quoted <note date=12/11/2007> <to>Tove</to> <from>Jani</from> </note> attribute <note date="12/11/2007"> <to>Tove</to> <from>Jani</from> </note>
XML Syntax Rules 7. XML elements can have entity references <message> salary < 1000 </message> <message> salary < 1000</message> Entity references begins with & and ends with semicolon
XML Syntax Rules 8. XML comments are similar to HTML <!-- This is a comment -->
XML Namespace XML namespace is a set of unique names XML namespace provides a method to avoid name conflicts
XML Namespace
XML Namespace <root> <h: table xmlns: h="http: //www. w 3. org/TR/html 4/"> <h: tr> <h: td>Apples</h: td> <h: td>Bananas</h: td> </h: tr> </h: table> <f: table xmlns: f="http: //www. w 3 schools. com/furniture"> <f: name>African Coffee Table</f: name> <f: width>80</f: width> <f: length>120</f: length> </f: table> </root>
XML Namespaces can also be declared in root element <root> xmlns: h="http: //www. w 3. org/TR/html 4/" xmlns: f="http: //www. w 3 schools. com/furniture" <h: table> <h: tr> <h: td>Apples</h: td> <h: td>Bananas</h: td> </h: tr> </h: table> <f: table > <f: name>African Coffee Table</f: name> <f: width>80</f: width> <f: length>120</f: length> </f: table> </root>
XML display using CSS XML File CSS File <? xml-stylesheet type=“text/css“ href=“filename. css“? >
XML DTD is referred to as Document Type Declaration The purpose of DTD is to define structure of XML document XML DTD defines the structure with a list of legal elements
XML DTD #PCDATA - Parse-able Character Data
Uses of XML DTD With a DTD, independent groups of people can agree to use a standard DTD for interchanging data. With a DTD, you can verify that the data you receive from the outside world is valid. You can also use a DTD to verify your own data. DTD Internal DTD External DTD
Sources 1. www. w 3 schools. com 2. www. tutiorialspoint. com
- Slides: 23