Search code examples
xhtmldtdinvalid-charactersdtd-parsing

Xhtml Invalid Characters?


I have made custom xhtml valdidator in .NET(validating through dtd + some extra rules) and I have noticed a discrepancy between my validation and w3c validation.

In my validator I get the following error when there is colon in the id (let's say : id="mustang:horse")

(Error) The 'id' attribute has an invalid value according to its data type.

But I do not get any errors on w3c for this pattern.

I tried to find a list of invalid characters for an attribute in xml/xhtml but couldn't find it?

Thank you for your help,


Solution

  • The reason for this difference is that W3C validator doesn't seem to do namespace aware XHTML processing. Although XHTML documents need to be in the XHTML namespace, this is actually reasonable, because HTML documents are not using namespaces and the normative valid structure of XHTML documents (as HTML) is defined by a DTD file and DTDs are not actually namespace aware.

    Like @Alochi already noted:

    Values of type ID MUST match the Name production.

    This is true when the document is parsed as not namespace aware, but it is not true if the document needs to be namespace conformant. The Namespaces in XML specification states that IDs must match NCName production which explicitly forbids the colon character. Namespace aware parsing is a common convention and therefore using a colon in the value of a id is not recommended even though it is allowed when the document parsing is not namespace aware .

    Summary: if namespaces are ignored, an ID value must be a valid Name and it can contain a colon; otherwise it must be a valid NCName and it can't contain a colon.