|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-12 00:34 UTC] swappp at yandex dot ru
Description:
------------
DOMDocument::load($xml_doc_node->saveXML());
It works normal...
Reproduce code:
---------------
$xml_doc_node = new DOMDocument('1.0', "UTF-8");
$xml_style = $xml_doc_node->createProcessingInstruction('xml-stylesheet');
$xml_doc_node->appendChild($xml_style);
$xml_style->nodeValue = 'href="html.xsl" type="text/xsl"';
$xml_page = $xml_doc_node->createElement('document');
$xml_doc_node->appendChild($xml_page);
$element = $xml_page->appendChild(new DOMElement('old-html'));
$div = $element->appendChild(new DOMElement('div', 'test'));
$div->setAttribute('xmlns','http://www.w3.org/1999/xhtml');
$xsl = DOMDocument::loadXML('<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes" encoding="UTF-8"/>
<xsl:template match="/document">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru"><body><xsl:apply-templates/></body></html>
</xsl:template>
<xsl:template match="/document/old-html"><xsl:copy-of select="*"/></xsl:template>
</xsl:stylesheet>');
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml_doc_node);
Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<body>
<div>test</div>
</body>
</html>
Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<body>
<div xmlns="" xmlns="http://www.w3.org/1999/xhtml">test</div>
</body>
</html>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 09:00:01 2025 UTC |
Thanks. But it is the simplified code. Origianl: $dom_html = DOMDocument::loadHTML('<div xmlns="http://www.w3.org/1999/xhtml">'.$content.'</div>'); $xp = new DOMXPath($dom_html); $body = $xp->query("/html/body/*"); foreach ($body as $tag) { $tag = $element->appendChild($element->ownerDocument->importNode($tag, true)); } LoadHTML() don't support XHTML? And why loadHTML don't set document namespace? P.S. Sorry for my bad English.loadHTML is for HTML 4.0 documents, which have no namespace by specifications... If it's really XHTML, use loadXML But your real problem is this: $div->setAttribute('xmlns','http://www.w3.org/1999/xhtml'); That doesn't work. You can't set namespaces this way. There's no way actually in DOM to move an element from one namespace to another without rebuilding it . chregu