I have a website that a client requires to be XHTML valid. They check it using the W3C validator.
I want to add my own namespace and attributes so I can do things like this:
<div my:userid="123"> ... </div>
From what I understand, defining custom namespaces is perfectly valid XHTML, as long as I do this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:my="http://www.example.com/my">
However, my XHTML fails validation. The problem appears to be that the validator does not actually go out and check my custom DTD document for my custom namespace, it only checks the XHTML against known DTD's. Anyone able to shed any light on how I can solve this problem?
Nope. Custom namespaces are perfectly well-formed in XML, but ‘valid’ has the specific meaning that every element and attribute used is declared in the document's schema. That schema can be a DTD, an XML Schema, or something else, but you've got to declare it.
So you can declare your own schema to add custom attributes to the language, and indeed XHTML Modularization makes this very easy. You'd have to add the reference to the DTD as a <!DOCTYPE> in the prolog; just setting namespace URIs doesn't give an XML processor any hook to find the schema in itself.
But then what you've written is “valid my-language-which-is-a-bit-like-XHTML”, and not “valid XHTML”. Some of these ‘my-languages’ are well-known, like ‘XHTML+MathML+SVG’, but it's still not XHTML as such and if your client is dead set on “valid XHTML” you can't use any of them.
You've also got potential browser problems, particularly with IE, which (pre-IE8) does some weird things with the Element.*etAttribute* family of DOM calls. And unless you're actually serving the document as an XML Content-Type (which IE also can't handle), all of your namespace stuff isn't actually using namespaces anyway.
In [X]HTML5 there is a proposal to allow user custom attributes (primarily for scripting purposes) to go in attributes whose names start with ‘data-’. But in the meantime the usual method is to hide values in another attribute, for example class:
and then extract the data using suitable string processing over className in script.
1.0 not allowed this .if you really want to do this you should download existing dtd and save it in your server and define private instead of public. but w3c validation not passed because it validate against the orginal one only
For XHTML 1.0 you are restricted to XHTML 1.0 elements and attributes:
Normative Definition of XHTML 1.0
My understanding is that XHTML 2.0 aims at providing a framework for doing what you want.
I've had some success with the W3C validator using, not
xmlns=
, but taking the standard XHTML DTD and adding a few attributes at the end as bobince describes above. I am using this to add attributes used by the PHPTAL templating system, such asI agree that what you need is not XHTML but a superset of XHTML. However, if your client is prepared to test simply by pointing the W3C validator at your URL, then go ahead. For advice, see WDG