Introduction XML
Introduction XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML AND HTML
• XML and HTML were designed with different
goals:
• 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 like HTML tags
are
STRUCTURE OF XML DOCUMENT
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
XML SYNTAX
XML Documents Must Have a Root Element
XML documents must contain one root element that is the parent of all other
elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
The XML Prolog
The XML prolog is optional. If it exists, it must come first in the document.
All XML Elements Must Have a Closing Tag
<p>This is a paragraph.</p>
<br />
XML Tags are Case Sensitive
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
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
Entity References
<price>29.99</price>
<element></element>
<element />
<person gender="female">
or like this:
<person gender='female'>
If the attribute value itself contains double quotes you can use single
quotes, like in this example: