1.7 Whitespace
Whitespace characters in XML are space, tab, carriage return, and line feed characters. XML requires that whitespace be used to separate attributes and namespace declarations from each other and from the element tagname. Whitespace is also required between the target and data portion of a processing instruction and between the text portion of a comment and the closing comment character sequence (-->) if that text ends with a hyphen (-). XML allows whitespace inside element content, attribute values, processing instruction data, and comment text. Whitespace is also allowed between an attribute name and the equal character and between the equal character and the attribute value. The same is true for namespace declarations. Whitespace is allowed between the tagname of an open or close tag and the ending character sequence for that tag. Whitespace is not allowed between the opening less-than character and the element tagname or between the prefix, colon, and local name of an element or attribute. Nor is it allowed between the start processing instruction character sequence <? and the target.
Examples
Legal use of whitespace
<pre:Vehicle xmlns:pre='urn:example-org:Transport' type='car' > <seats> 4 </seats> <colour> White </colour> <engine> <petrol /> <capacity units='cc' >1598</capacity> </engine > </pre:Vehicle >
Whitespace used in various places in an XML document: between the tagname, namespace declaration, attribute, and closing greater-than character on the top-level element start tag, between each element, in the character content of the seats and colour elements, between the tagname and the /> sequence of the petrol element, between the tagname and the closing greater-than character of the end tag for the engine element and the top-level element.
Illegal use of whitespace
<pre :Vehicle xmlns:pre='urn:example-org:Transport' type='car'> < seats>4</ seats> </pre:Vehicle>
Whitespace used incorrectly in various places in an XML document: between pre and :Vehicle in the start tag of the top-level element, between xmlns: and pre of the namespace declaration of the top-level element, between the opening less-than character and seats in the start tag of the child element, and between </ and seats in the end tag of the child element.