I know how white space is handled in text nodes for XML and HTML, but I'm uncertain about white spaces inside tag elements themselves. Obviously, white spaces are used inside tags to separate attributes, but is it valid to have white spaces after '<' or before '>'?
For example:
< foo > < /foo >
Or even:
<foo> < / foo >
Are these tags valid XML? What about HTML, assuming they were actual HTML tag names?
In XML documents, there are two types of whitespace: Significant whitespace is part of the document content and should be preserved. Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document.
As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.
White space in XML is any character from the following set: space, tab and blank line/new line (except hard return). White space serves the following purposes: Visually format the document in its source form, such as for code, to denote semantic significance for the XML document.
@fakaff: Yes, that is valid. Line breaks, tabs and spaces are all white space characters, and you can have as much white space as you like after the tag name and between attributes (and even around the = in an attribute).
The specification (section 3.1 Start-tags, end-tags, and empty-element tags) says that there is no white space between the '<'
and the tag name, between '</'
and the tag name, or inside '/>'
. You can add white space after the tag name, though:
<foo > </foo > <bar />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With