I want to validate XML templates that are a XHTML extension. Now there are special characters like { and | in ID attributes. Is it possible to extend the XHTML DTD to overwrite the restriction to the characters allowed in the ID attribute? Or are the characters defined by the XML specification?
I want to validate XML templates that are a XHTML extension. Now there are
Share
You cannot use the characters ‘{‘ and ‘|’ directly in id attributes because in the XML specification it says
The name production is here. If you expand the syntax rule you see that the only characters allowed in a name are given by these productions:
Unfortunately the left brace and the pipe are not allowed. The codepoints for those characters are #7B and #7C respectively; not in the accepted character ranges.
TL;DR: the legal characters for ID attributes are owned by the XML spec and your two characters are not legal.
ADDENDUM
Here are some examples. The following document passes validation for XHTML on the W3C validation site:
but the following will not
We get the error:
Now it’s rather interesting that if you really want the left curly bracket in the id name, you can try this:
But you get the same error! You might want to try this; the validator shows the line with the ampersand hash x seven b semicolon but it thinks there is a left brace there.
The bottom line is that you simply cannot have ids with characters other than those allowed by the XML specification.