You are here: XHTML with DOMImplementation weirdness « PHP Programming Language « IT news, forums, messages
XHTML with DOMImplementation weirdness

Posted by mislav.marohnic on 12/05/05 01:11

In short, I want to create XHTML documents. Creating XML objects with
DOMDocument constructor doesn't quite cut it because you need
DOMImplementation to create a DOCTYPE.

Here is how everyone sane would do it:

$doctype = DOMImplementation::createDocumentType(
'html'
,'-//W3C//DTD XHTML 1.0 Strict//EN'
,'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
);
$doc = DOMImplementation::createDocument(null, 'html', $doctype);
$doc->formatOutput = true;
$doc->encoding = 'UTF-8';
$doc->documentElement->setAttribute('lang', 'en');
$head = $doc->createElement('head');
$body = $doc->createElement('body');
$doc->documentElement->appendChild($head);
$doc->documentElement->appendChild($body);

OK, so now we have HEAD and BODY inside HTML. So far so good. But
here's the strange part: on output (saveXML() or saveHTML) a META tag
appears inside the HEAD:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Obviously we haven't created this META tag. So who did? Where did it
come from? I didn't want text/html, I want application/xhtml+xml, so I
tried to explicitly override it:

$meta = $this->doc->createElement('meta');
$meta->setAttribute('http-equiv', 'Content-Type');
$meta->setAttribute('content', 'application/xhtml+xml; charset='.$enc);
$head->appendChild($meta);

No use. On every output my META Content-Type tag gets overriden by the
generated META tag.

Manipulating DOM with PHP5 is poorly documented and not much discussed,
which probably means a few people use it. I hope someone can clear out
this oddity for me for it looks like a feature, not a bug.

I wouldn't like to believe that the only solution to change the
content-type is str_replace() after outputting to a string :(

--
Mislav

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация