function XML_Template_process($node, $obj, $clean = 1)
{
if (is_a($obj, 'DOMNode')) { # overwrite
- while ($node->childeNodes->length > 0) {
+ while ($node->childNodes->length > 0) {
$child = $node->childNodes->item(0);
$node->removeChild($child);
}
XML_Template_process($frag, array(), $clean);
$node->appendChild($frag);
} else if (!is_array($obj)) { # overwrite
- for ($i = 0; $i < $node->childNodes->length; ++$i) {
- $child = $node->childNodes->item($i);
- $node->removeChild($child);
+ while ($node->childNodes->length > 0) {
+ $node->removeChild($node->firstChild);
}
$doc = $node->ownerDocument;
$node->appendChild($doc->createTextNode($obj));
} else if (is_associative_array($obj)) { # substitute
- for ($i = 0; $i < $node->childNodes->length; ++$i) {
+ $num_children = ($node->childNodes == null) ? 0 : $node->childNodes->length;
+ for ($i = 0; $i < $num_children; ++$i) {
$child = $node->childNodes->item($i);
$processed = false;
return $array;
}
-# Ideally, this would be "return $obj->clone_node(true)". But surprise, surprise,
-# PHP is buggy (at least both PHP4 and PHP5); it removes the prefix information
-# from all attributes during a clone. IOW, we'll have to clone evverything
-# ourselves.
+# Ideally, this would be "return $obj->clone_node(true)". But surprise,
+# surprise, PHP is buggy; it does not preserve the prefix information on
+# attributes properly during a clone. (PHP4 and PHP5 are broken in different
+# ways here...) IOW, we'll have to clone everything ourselves.
function own_clone_node($node, $doc)
{
// we only need these two
} else {
$attr2 = $doc->createAttribute($attr->localName);
}
- $attr2->value = $attr->value;
+
+ # You've got to be kidding me...
+ $attr2->value = htmlentities($attr->value);
$newnode->appendChild($attr2);
}
}