Jump to content

W3 Schools XML validator accepting invalid xml


sancho2

Recommended Posts

W3Schools may be wrong.

 

I don't see any restriction on element names in the XML specification: https://www.w3.org/TR/REC-xml/#NT-Name

 

Update:

It seems there is a description here:

https://www.w3.org/TR/REC-xml/#NT-S

 

Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification.

 

This means that it's recommended that you don't use it for custom elements, but it's not technically invalid. If a future version of XML appears using <xml> tags for system reasons your XML document may behave incorrectly, that's the only drawback of naming your elements with "xml".

Edited by Ingolme
Link to comment
Share on other sites

Fair enough.

I would only recommend updating the second page I linked as it quite clearly states that element names must follow the naming rules and number 3 is this:

 

Element names cannot start with the letters xml (or XML, or Xml, etc)

Link to comment
Share on other sites

Thanks for the links by the way.

I have another question with regards to the declaration.

The w3schools validator is accepting declarations that begin with <?xml but will also accept any valid tag character after xml.

For example the validator accepts

<?xmlstu12345 version="1.0" encoding="UTF-8"?>

as a valid declaration.

Another online validator shows the obvious error.

This is how it is described on the W3C Recommendation page you linked.:

 

XMLDecl ::= '<?xml'

Edited by sancho2
Link to comment
Share on other sites

The validator on W3Schools is actually making use of your browser's own built-in XML parser, so it's not W3Schools' fault if the parser lets something past, but this isn't actually an error.

 

The structure you represented (<?xmlstu12345 version="1.0" encoding="UTF-8"?>) is called a processing instruction. It's described in this part of the specification: https://www.w3.org/TR/REC-xml/#dt-pi

Any structure with the format <?something ... ?> is a processing instruction.

 

Some XML parsers will complain about the missing <?xml ?> declaration, but others accept XML documents that don't have one even though it's required by the specification.

Link to comment
Share on other sites

The other online validator I tried is

http://codebeautify.org/xmlvalidator

I now see that it isn't complaining about an invalid declaration, but it is complaining about 'xml' being the first letters in a processing instruction. And that goes back to 'xml' being reserved.

(After reading more of the W3C Recommendation) Isn't it the case that 'xml' is reserved but only for processing instructions?

If that is the case then the W3Schools page on xml tag name rules has got it completely wrong (regarding point 3).

And Firefox (Expat Parser) is either mis-handling the processing statement validation or deliberately ignoring this rule.

 

I realize this issue is of little importance. I am just trying to better understand what is correct.

 

If you were writing an XML Parser would you:

A. Allow the letters 'xml' to preface either processing instructions or tag names.

B. Invalidate only processing instructions prefaced with the letters 'xml' (allow them for tag names).

C. Other

 

Again, I thank you for your time answering my questions.

Edited by sancho2
Link to comment
Share on other sites

If I were writing the parser I would look at the EBNF descriptions on the specification page I linked you to. I think the rules do not allow "xml" as a name for a processing instruction or element name.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...