summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-06 05:32:03 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-06 05:32:03 (GMT)
commitf26764b3d1f63255a56a4289559ba213362389b4 (patch)
treea93b8f2ac096c6b6f3aae37b992939b30b62bb8d
parentf7010f673ef32f8b76ca2d4029e60133b693050b (diff)
downloadblogengine-f26764b3d1f63255a56a4289559ba213362389b4.zip
blogengine-f26764b3d1f63255a56a4289559ba213362389b4.tar.gz
blogengine-f26764b3d1f63255a56a4289559ba213362389b4.tar.bz2
Work around XML::LibXML / libxml2 limitation with namespace declarations.
-rwxr-xr-xdaml2html.pl28
1 files changed, 25 insertions, 3 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 9baf97c..51e7808 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -146,6 +146,26 @@ $doc->removeExternalSubset();
$doc->removeInternalSubset();
$doc->createInternalSubset("html", XHTML_PUBID, XHTML_URI);
+# The following is a cruft to work around XML::LibXML limitations:
+# there seems to be no way to eliminate namespace declarations which
+# have become unnecessary; so, instead, we prevent them from appearing
+# by placing the entire tree ($true_root) as the single child of a
+# root1 element which contains the relevant prefix declarations, and
+# that is itself the single child of a root0 element which has _no_
+# prefix declarations. We work entirely within root1 except at the
+# very end when we do the following trick: move $true_root outside of
+# $root1 (by $root0->appendChild($true_root)), which forces namespace
+# declarations to be made only as necessary, and then make $true_root
+# the document element. Yuck!
+my $true_root = $doc->documentElement;
+my $root0 = $doc->createElement("root0");
+$doc->setDocumentElement($root0);
+my $root1 = $doc->createElement("root1");
+$root1->setAttributeNS(XML_XMLNS_NS, "xmlns", XHTML_NS);
+$root1->setAttributeNS(XML_XMLNS_NS, "xmlns:d", DAML_NS);
+$root0->appendChild($root1);
+$root1->appendChild($true_root);
+
my $xpc = XML::LibXML::XPathContext->new($doc);
$xpc->registerNs('h', XHTML_NS);
$xpc->registerNs('d', DAML_NS);
@@ -174,7 +194,7 @@ $xpc->registerNs('d', DAML_NS);
# node and shifts them at the beginning of @todo_stack.
my @todo_stack;
-unshift @todo_stack, [undef, $doc->documentElement, {}, {is_root=>1}];
+unshift @todo_stack, [undef, $true_root, {}, {is_root=>1}];
# Global variables for processing:
my $uri_to_top;
@@ -468,7 +488,8 @@ sub daml_handler {
if ( defined($lang = get_node_lang_norec $node) ) {
set_node_lang_norec $html_node, $lang;
}
- $doc->setDocumentElement($html_node);
+ $true_root->replaceNode($html_node);
+ $true_root = $html_node;
$html_node->appendChild($doc->createTextNode("\n"));
$html_node->appendChild($doc->createComment(" This file is automatically generated. Do not edit! "));
$html_node->appendChild($doc->createTextNode("\n"));
@@ -972,7 +993,6 @@ sub wref_attr_handler {
my $tgt = $attr->nodeValue;
$attr->unbindNode;
$pnode->setAttributeNS("", "href", $tgt);
- decontaminate_node $pnode;
}
my %daml_handler = (
@@ -1035,4 +1055,6 @@ while ( my $process = shift @todo_stack ) {
}
}
+$root0->appendChild($true_root);
+$doc->setDocumentElement($true_root);
print $doc->toString;