It is valid in general, but may not be in specific.
There are not many rules for what is allowed as a value. Without any specific restrictions based on the document type, attribute values must match the description of valid character data in the section Character Data and Markup of the xml specification. Essentially this says that the characters & and < are not allowed (but can be escaped with &
and <
). Some processors may balk on a > character as well, but this is allowed (except when it appears in ]]>
in which case it must be escaped with >
). Any other data is allowed (with some escaping needed in some cases where quotation marks are mixed).
Now, depending on the application, there may be further restrictions on the values of attributes. For example, the ID type, must match the specification for a Name production. These must start with a letter (or one of a small number of punctuation characters) and continue with numbers, letters, or punctuation characters. In this case spaces would NOT be allowed.
There are addition possible restrictions covered in the specification (which may apply depending on the application), and further restrictions may be imposed by various schemas.
The comment by Kai Wu Toh provided a link to another question which covered the additional restrictions provided by HTML.
Links to the specification are provided in the answer, but to make the relevant sections easier to find if the links stop working, they are summarized here.
- Character Data and Markup is covered in section 2.4 of the XML 1.0 specification
- The ID validity constraint is covered in section 3.3.1 of the specification.
- The Name production is covered in section 2.3 of the specification.
The specification can be found at https://www.w3.org/TR/REC-xml.
An annotated version of the specification can be found at http://www.xml.com/axml/testaxml.htm.