[html5] XHTML extending. id, class, style attributes support for other namespaces

Anton Vitr anton.vitr at yandex.ua
Tue Oct 16 09:09:49 PDT 2012


Hello all !

Context:
We are planning to build client-side javascript ui controls library.
Also, we want to achieve declarative syntax for our custom controls, like using extended XHTML similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mylib="http://mylib.com">
        <head>
                <script type="text/javascript" src="mylib.js"></script>
        </head>
        <body>
                <mylib:pagetitle>My Title</mylib:pagetitle>
                <span>some text</span>
        </body>
</html>

Problem:
Standard attributes "id", "class", "style" is not not supported on tags from different namespace by modern browsers in XHTML mode. Example:
<mylib:pagetitle id="my" class="some" style="color:red">My Title</mylib:pagetitle>

Research shown that browsers work correctly (following w3c spec):
1. They may treat that attributes as related to different namespace: "http://mylib.com" instead of "http://www.w3.org/1999/xhtml".
2. getElementById is not belong to XML world. It may work if attribute have ID type regardless attribute name. Or xml:id w3c spec exist, hoverer It also do not work in modern browsers.
   * https://developer.mozilla.org/en-US/docs/xml/xml:id
3. "class" is not belong to XML world, so CSS can be written using XPath "[class~='some']" instead of ".some" selector.
   * http://stackoverflow.com/questions/2151615/can-you-style-xhtml-elements-in-another-namespace-using-id-and-class-name-css-se
4. I don't find why style is not supported. Styling of those tags even impossibly using plain java-script. like element do not have even style property in javascript.
Note: I don't find described problems in http://wiki.whatwg.org/wiki/HTML_vs._XHTML page.

Question:
1. How can I tell browser to treat <mylib:pagetitle> just like HTML div, with id, class, style support?
2. Did I miss soothing, and some like DTD or XML schema can fix this?
3. XHTML extending need to be done in other way?

I've even tried following, but with no luck:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mylib="http://mylib.com">
        <head>
                <script type="text/javascript" src="mylib.js"></script>
        </head>
        <body>
                <mylib:pagetitle :id="my" xml:id="my" html:id="my" style="color:red" html:style="color:red">My Title</mylib:pagetitle>
                <span>some text</span>
        </body>
</html>

Only option I see - it is use common HTML mode instead of XHTML, thus, loosing namespacing.

Best regards,
Anton Vitr



More information about the Help mailing list