Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

@ added cloneNode

- fixed functions cloneNode, removeChild and replaceChild to return a result object of a single node instead
  of the raw domxml node so that they can be used with the XML_XPath functions


git-svn-id: http://svn.php.net/repository/pear/packages/XML_XPath/trunk@92238 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 0cb1c1d3905d3da55d7116fed0d28cb5bf6f4ad0 1 parent 94f3287
Daniel Allen authored
Showing with 34 additions and 3 deletions.
  1. +34 −3 XPath/common.php
View
37 XPath/common.php
@@ -884,7 +884,6 @@ function appendData($in_content, $in_xpathQuery = null, $in_movePointer = false)
*
* @access public
* @return object pointer to old node {or XML_XPath_Error exception}
- * [!] I should make it so an xml_xpath_result is returned or something [!]
*/
function replaceChild($in_xmlData, $in_xpathQuery = null, $in_movePointer = false)
{
@@ -920,7 +919,7 @@ function replaceChild($in_xmlData, $in_xpathQuery = null, $in_movePointer = fals
$this->_restore_bookmark();
}
- return $oldNode;
+ return new XML_XPath_result(array($oldNode), XPATH_NODESET, null, $this->ctx, $this->xml);
}
// }}}
@@ -959,6 +958,7 @@ function appendChild($in_xmlData, $in_xpathQuery = null, $in_movePointer = false
if (XML_XPath::isError($importedNodes = $this->_build_fragment($in_xmlData))) {
return $importedNodes;
}
+
foreach($importedNodes as $index => $importedNode) {
$node = $this->pointer->append_child($importedNode);
if ($index == 0) {
@@ -1053,10 +1053,41 @@ function removeChild($in_xpathQuery = null, $in_movePointer = false)
$this->_restore_bookmark();
}
- return $removedNode;
+ return new XML_XPath_result(array($removedNode), XPATH_NODESET, null, $this->ctx, $this->xml);
}
// }}}
+ // {{{ object cloneNode()
+
+ /**
+ * Clones the node and return the node as a result object
+ *
+ * @param bool $in_deep (optional) clone node children
+ * @param string $in_xpathQuery (optional) quick xpath query
+ * @param boolean $in_movePointer (optional) move internal pointer
+ *
+ * @access public
+ * @return object cloned node of the current node, ready to be put in another document
+ */
+ function cloneNode($in_deep = false, $in_xpathQuery = null, $in_movePointer = false)
+ {
+ if (!$this->pointer) {
+ return PEAR::raiseError(null, XML_XPATH_NULL_POINTER, null, E_USER_WARNING, '', 'XML_XPath_Error', true);
+ }
+
+ if (XML_XPath::isError($result = $this->_quick_evaluate_init($in_xpathQuery, $in_movePointer))) {
+ return $result;
+ }
+
+ $clonedNode = $this->pointer->clone_node($in_deep);
+
+ if (!is_null($in_xpathQuery) && !$in_movePointer) {
+ $this->_restore_bookmark();
+ }
+
+ return new XML_XPath_result(array($clonedNode), XPATH_NODESET, null, $this->ctx, $this->xml);
+ }
+ // }}}
// {{{ void replaceChildren()
/**
Please sign in to comment.
Something went wrong with that request. Please try again.