Browse files

@ added childNodes() which takes the current pointer and returns all …

…of the non-blank (if set)

children as an xml_xpath_result object so that the result object functions can be used to
step through the results...one disadvantage right now is that since it is not an actually xpath
query, I can't resort the results, so that result function will be broken when the result object
is generated in this manner...hang in there, I am working on this...


git-svn-id: http://svn.php.net/repository/pear/packages/XML_XPath/trunk@84681 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent bdd18b4 commit 469160ff9e2e76bf3715bde736ded99467bd9873 Daniel Allen committed Jun 5, 2002
Showing with 39 additions and 0 deletions.
  1. +39 −0 XPath/common.php
View
39 XPath/common.php
@@ -252,6 +252,45 @@ function siblingNode($in_name, $in_index = 1, $in_movePointer = true, $in_clearC
}
// }}}
+ // {{{ object childNodes()
+
+ /**
+ * Retrieves the child nodes from the element node as an XML_XPath_result object
+ *
+ * Similar to an xpath query, this function will grab all the first descendant child
+ * nodes of the element node at the current position and will create an XML_XPath_result
+ * object of type nodeset with each of the child nodes as the nodes.
+ *
+ * @param string $in_xpathQuery (optional) quick xpath query
+ * @param boolean $in_movePointer (optional) move the internal pointer with quick xpath query
+ *
+ * @access public
+ * @return object XML_XPath_result object of type nodeset
+ * [!] important note: since we had to hack the result object a bit, you cannot sort the
+ * result object when generated in this manner right now [!]
+ */
+ function &childNodes($in_xpathQuery = null, $in_movePointer = false)
+ {
+ if (XML_XPath::isError($result = $this->_quick_evaluate_init($in_xpathQuery, $in_movePointer, array(XML_ELEMENT_NODE)))) {
+ return $result;
+ }
+
+ // since we can't do an actual xpath query, we need to create a pseudo xpath result
+ $xpathObj = new StdClass();
+ $xpathObj->type = XPATH_NODESET;
+ foreach($this->pointer->child_nodes() as $childNode) {
+ // if this is a blank node and we are skipping blank nodes...skip to next child
+ if ($childNode->is_blank_node() && $this->skipBlanks) {
+ continue;
+ }
+ $xpathObj->nodeset[] = $childNode;
+ }
+ $resultObj =& new XML_XPath_result($xpathObj, null, $this->xml, $this->ctx);
+ $this->_quick_evaluate_shutdown($in_xpathQuery, $in_movePointer);
+ return $resultObj;
+ }
+
+ // }}}
// {{{ boolean childNode()
/**

0 comments on commit 469160f

Please sign in to comment.