X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=php5%2Fxml-template.php;h=e6a4e1909d2f0dc4153fbd644ec6797b0040587c;hb=1725768e2eaf68a1445f1aef9d95da0bf461e88b;hp=ed1e8f85529fc389120184c8023dee97a516518a;hpb=a65b22fc1dd7fe224ec09df1c4846334c8ad1ab9;p=xml-template diff --git a/php5/xml-template.php b/php5/xml-template.php index ed1e8f8..e6a4e19 100644 --- a/php5/xml-template.php +++ b/php5/xml-template.php @@ -32,8 +32,13 @@ function XML_Template_process($node, $obj, $clean = 1) $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) { @@ -44,14 +49,13 @@ function XML_Template_process($node, $obj, $clean = 1) 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 @@ -134,7 +138,7 @@ function XML_Template_clean($node) 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); } @@ -204,7 +208,7 @@ function own_clone_element($node, $doc) } # You've got to be kidding me... - $attr2->value = htmlentities($attr->value); + $attr2->value = preg_replace("/&/", "&", $attr->value); $newnode->appendChild($attr2); } }