Following rules apply to an XML document with valid element and attribute properties.
XML Elements
In XML document the elements are said to be well formed if:
- Opening tag is subsequently closed.
- If there is any empty element, it has to be terminated.
- The nested tags should not overlap and should be properly nested.
- A single element called root element contains all other elements.
- All elements are well formed.
Example of well-formed XML elements
<earth>
<country><b>Russia</b></country>
<capital>Moscow</capital>
<area>11.5</area>
</earth>
Example of non-well-formed XML elements
<earth>
<country><b>Russia</country></b> -> Elements not nested properly
<capital>Moscow</capital>
<area>11.5</area>
<br> -> Empty element, not closed.
</Earth> -> Ending element has different name.
XML Attributes
The attributes add extra information to the elements. The well formed XML attributes have following characteristics:
- It has to be single or double quoted.
- Attributes cannot have multiple values and can appear at most once on each element.
- If more than one value is desired (example, CSS class names or identifier names) it should be well-formed with some format which does not cause parsing error in XML and the quotes does not cause problem.
- Attributes cannot have tree structure.
- The attribute values are separated by comma or semi-colon or space–delimited list.
Example of well-formed XML attributes
The example shows multiple attribute names and attribute name “class” has multiple values “style1” and “style2”. This is well-formed attribute.
<earth totalArea="100">
</earth>
<div class=”style1 style2”>
</div>
Example of non well-formed XML attributes
<earth totalArea="100" population=”100”>
</earth>
Comments
No comments have been made yet.
Please login to leave a comment. Login now