By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,318 Members | 581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,318 IT Pros & Developers. It's quick & easy.

Validate (X)HTML with custom tags with PHP DOM API

P: 27

I have defined a set of custom tags that I put among regular HTML tags. E.g.

<div id="regular_id">
<namespace:container id="something" type="article" />

At this time, I use PHP preg_* functions to parse the HTML file and trigger actions when I detect a tag that starts with the string "namespace:".

It works but I feel that I can do better with PHP DOM API :
Question : am I right on this ?

1) I would like to create either a DTD or a Schema for my custom tags and validate my HTML file against this.

I thought I could modify the official DTD for XHTML1.1 (transitional) and define my custom tags in it.

But then I might lost the benefits of namespaces since my custom tags will be merged with the regular HTML tags ?

2) I would like to use DOMDocument::getElementsByTagNameNS() to retrieve all my custom tags.

I don't know what's the best strategy.

All advises appreciated, code sample also ;-)

Thank you.
Dec 17 '08 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
there is no XHTML 1.1 transitional DTD (there's only one DTD for XHTML 1.1)

you can write your own DTD using the official one as a base or extend/redefine some of the official elements. the question is, if the browsers support that (a question to Dr. Google).

you wouldn't. a DTD simply checks, if a document conforms to a given structure. not more, not less. the benefit of namespaces is not affected by a DTD.

if these elements only trigger some server side action, remove them before you send the document to the browser. all that will be left is XHTML.

sounds reasonable. code samples you'll find here


note: IE doesn't support XHTML (i.e. it doesn't support the XHTML MIME type (and probably never will)) so make sure IE will be given an according document. (if you have XHTML 1.1 you probably know, what MIME type should be served (if not, see XHTML Media Types))
Dec 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.