Well-formed XML
- Last UpdatedJan 27, 2023
- 1 minute read
When an XML document applies to all the rules that is set up for a valid XML document, it is said to be a well-formed XML document. We have already mentioned some of those rules:
-
All start tags must have a matching end tag
-
XML is case sensitive
-
Attribute values must be enclosed within double quotes
There are many more rules. The complete definition of XML can be found on the web site of the World Wide Web Consortium: www.w3c.org
In this document we will only mention the basics.
Free Layout
The layout of an XML document is free. An XML parser does not care about new line and extra blanks. The following two documents are equivalent:
Document 1
<Ship>
<Defaults Surface="SPHULL" XMin="FR40" YMin="0" XMax="FR80"/>
<HullCurve ObjId="SPX951">
<ByPrincipalPlane X="FR30"/>
</HullCurve>
</Ship>
Document 2
<Ship><Defaults Surface="SPHULL" XMin="FR40" YMin="0" XMax="FR80"/><HullCurve ObjId="SPX951"><ByPrincipalPlane X="FR30"/></HullCurve></Ship>
Nested Tags are Not Allowed
Another special feature of XML is that tags may not be nested, the following document is not well-formed XML:
<Ship>
<HullCurve>
</Ship>
</HullCurve>
Free Order of Attributes
The attributes of an element can always be given in an arbitrary order. The next two elements are equivalent:
<Box XMin="FR10" XMax="FR100" YMin="0" YMax="5000"/>
<Box YMax="5000" YMin="0" XMax="FR100" XMin="FR10"/>