ownerDocument; } function clone_doctype($implementation, $document) { if ($document->doctype === NULL) { return NULL; } return $implementation->createDocumentType($document->doctype->name, $document->doctype->publicId, $document->doctype->systemId); } function append_text($node, $text) { $node->appendChild(document_of($node)->createTextNode($text)); } # Replace children of $node with $new_child. function replace_children($node, $new_child) { remove_children($node); $node->appendChild($new_child); } # Replace content of $node1 with content of $node2. function replace_content($node1, $node2) { remove_children($node1); while ($node2->hasChildNodes()) { $node1->appendChild($node2->firstChild); } } function remove_children($node) { while ($node->hasChildNodes()) { $node->removeChild($node->firstChild); } } function remove_node_shallow($node) { while ($node->hasChildNodes()) { $node->parentNode->insertBefore($node->firstChild, $node); } $node->parentNode->removeChild($node); } function get_element_with_attribute_ns($ns, $attr_name, $node) { if ($node === NULL || $node->nodeType !== XML_ELEMENT_NODE) { return NULL; } if ($node->hasAttributeNS($ns, $attr_name)) { return $node; } for ($child = $node->firstChild; $child !== NULL; $child = $child->nextSibling) { $res = get_element_with_attribute_ns($ns, $attr_name, $child); if ($res !== NULL) { return $res; } } return NULL; } function get_attributes_array($element) { $res = array(); for ($i = 0; ($attr = $element->attributes->item($i)) !== NULL; ++$i) { $res[] = $attr; } return $res; } function remove_attributes($element) { while ($element->hasAttributes()) { $element->removeAttributeNode($element->attributes->item(0)); } } function remove_markup_not_of_ns($node, $ns) { for ($child = $node->firstChild; $child !== NULL; $child = $next_sibling) { $next_sibling = $child->nextSibling; if ($child->nodeType === XML_ELEMENT_NODE) { remove_markup_not_of_ns($child, $ns); if ($child->namespaceURI !== $ns) { remove_node_shallow($child); } else { remove_attributes_not_of_ns($child, $ns); } } } } function remove_attributes_not_of_ns($element, $ns) { $i = 0; while (($attr = $element->attributes->item($i)) !== NULL) { if ($attr->namespaceURI !== NULL && $attr->namespaceURI !== $ns) { $element->removeAttributeNode($attr); $i = 0; } else { ++$i; } } } function remove_attributes_of_ns($element, $ns) { $i = 0; while (($attr = $element->attributes->item($i)) !== NULL) { if ($attr->namespaceURI === $ns) { $element->removeAttributeNode($attr); $i = 0; } elseif ($attr->namespaceURI === 'http://www.w3.org/2000/xmlns/' && $attr->value === $ns) { } else { ++$i; } } } function set_attributes($element, $attributes) { $replaced_attrs = array(); foreach ($attributes as $attr) { if ($element->hasAttributeNS($attr->namespaceURI, $attr->localName)) { $a = $element->getAttributeNodeNS($attr->namespaceURI, $attr->localName); $replaced_attrs[] = $a->cloneNode(TRUE); } $element->setAttributeNS($attr->namespaceURI, $attr->nodeName, $attr->value); } return $replaced_attrs; } # Get attribute without case-sensitivity. function get_case_attribute($element, $attribute_name) { $lower_attribute_name = strtolower($attribute_name); for ($i = 0; ($attr = $element->attributes->item($i)) !== NULL; ++$i) { if ($attr->namespaceURI === '' && strtolower($attr->localName) === $lower_attribute_name) { return $attr; } } return NULL; } function get_w2ml_attribute($element, $attribute_name) { $attr = $element->getAttributeNodeNS(W2ML_NS, $attribute_name); if ($attr === NULL && $element->namespaceURI === W2ML_NS) { $attr = $element->getAttributeNodeNS(NULL, $attribute_name); } return $attr; } function get_w2ml_attribute_value($element, $attribute_name) { $attr = get_w2ml_attribute($element, $attribute_name); return $attr ? $attr->value : NULL; } function qname($element, $ns, $local_name) { $prefix = $element->lookupPrefix($ns); return $prefix === NULL ? $local_name : $prefix.':'.$local_name; } ?>