Next:
XHTML
Up:
Lecture 8
Previous:
XML Document Structure
XML Syntax
XML tags
- are order sensitive
- are case sensitive
- are standalone or come in properly nested pairs
- have exactly one top level or root element
- quote all attribute values
- do not repeat attributes
Example
of several XML errors
<?xml version="1.0" encoding="UTF-8"?>
<item type=mango>
<price> 6 euros </Price>
<Description> nice
<weight> 127 grammes
</Description> </weight>
</item>
<item type="pear" quality="good" type="pear">
<price> 2.53 euros
</item>
One way of correcting these errors:
<?xml version="1.0" encoding="UTF-8"?>
<basket>
<item type="mango">
<price> 6 euros </price>
<Description> nice </Description>
<weight> 127 grammes </weight>
</item>
<item type="pear" quality="good">
<price> 2.53 euros </price>
</item>
</basket>
New element <basket> is introduced to get a solo root element.
XML parsers always reject bad XML unlike HTML parsers.