Is the XML attribute valid?

I have such a tag. In the attribute, it contains a space at the beginning. Is it correct to give space in an attribute? Please suggest it.

<p id=" 10">space found at the starting point of attribute.</p> <p id="10 ">space found at the end point of attribute.</p> 
+6
source share
2 answers

It is valid in general, but may not be specific.

There are not many rules for a valid value. Without any specific restrictions based on the type of document, attribute values ​​must match the description of valid character data in the Character Data and Markup section for the xml Specification. In essence, this suggests that the & & < characters are not allowed (but can be escaped with &amp; and &lt; ). Some processors may carry the symbol > , but this is allowed (unless it appears in ]]> , in which case it must be escaped with &gt; ). Any other data is allowed (with some acceleration it is required in some cases when quotation marks are mixed).

Now, depending on the application, there may be additional restrictions on attribute values. For example, the type of identifier must conform to the specification Name Production. They must begin with a letter (or one of a small number of punctuation marks) and continue with numbers, letters or punctuation characters. In this case, spaces will NOT be.

There are additional possible restrictions specified in the specification (which may apply depending on the application), as well as additional restrictions may be imposed by various schemes.

Comment Kai Wu Toh provided a link to yet another question , which indicated additional restrictions provided by HTML.


Links to the specification are given in the answer, but to facilitate the search for the relevant sections, if the links stop working, they are summarized here.

  • Character data and markup are described in section 2.4 of the XML 1.0 specification.
  • The validity constraint of an identifier is described in section 3.3.1 of the specification.
  • Name production is described 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 .

+1
source

XMLSpy says your XML is well formed. Therefore, there is clearly no problem with leading spaces in attribute values!

0
source

All Articles