tags:

views:

93

answers:

2

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 before the '<' or '>'?

For example:

<  foo  >
< /foo >

Or even:

<foo>
< /  foo >

Are these tags valid XML? What about HTML (assuming they were actual HTML tag names)?

+1  A: 

</ and /> are tokens, so whitespace between the two characters would be a syntax error. And as Guffa pointed out, whitespace isn't allowed between the opening token and the name. But you're fine adding whitespace between the element tag and the closing >(or />) token.

EDIT to reflect Guffa's correct citing of the XML specification.

Dan Breslau
+3  A: 

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
/>
Guffa
Oops. That'll teach me to double-check the spec... +1
Dan Breslau