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
$num_children = ($node->childNodes == null) ? 0 : $node->childNodes->length;
+ $children = array();
for ($i = 0; $i < $num_children; ++$i) {
- $child = $node->childNodes->item($i);
+ $children[] = $node->childNodes->item($i);
+ }
+
+ for ($i = 0; $i < $num_children; ++$i) {
+ $child = $children[$i];
$processed = false;
if ($child->nodeType == XML_ELEMENT_NODE) {
if (isset($attrs)) {
$replace_child = 0;
- foreach ($child->attributes as $attr) {
- if ($attr->namespaceURI == 'http://template.sesse.net/' && $attr->name == 'id') {
- $id = $attr->value;
- if ($clean) {
- $child->removeAttributeNode($attr);
- $replace_child = 1;
- }
- }
+ $id_node = $child->getAttributeNodeNS('http://template.sesse.net/', 'id');
+ if (isset($id_node)) {
+ $id = $id_node->value;
+ if ($clean) {
+ $child->removeAttributeNode($id_node);
+ $replace_child = 1;
+ }
}
# This seems to be the only way to reliably get rid of the excess
while ($node->childNodes->length > 0) {
$child = $node->childNodes->item(0);
$node->removeChild($child);
- $parent->insertBefore($child, $node);
+ $parent->insertBefore(own_clone_node($child, $doc), $node);
}
$parent->removeChild($node);
}
} else {
$attr2 = $doc->createAttribute($attr->localName);
}
- $attr2->value = $attr->value;
+
+ # You've got to be kidding me...
+ $attr2->value = preg_replace("/&/", "&", $attr->value);
$newnode->appendChild($attr2);
}
}