Skip to content

Commit

Permalink
@ added cloneNode
Browse files Browse the repository at this point in the history
- 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
Daniel Allen committed Aug 16, 2002
1 parent 94f3287 commit 0cb1c1d
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions XPath/common.php
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

// }}}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1053,9 +1053,40 @@ 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()

Expand Down

0 comments on commit 0cb1c1d

Please sign in to comment.