QueryPath\CSS\QueryPathEventHandler::elementNS PHP Method

elementNS() public method

Inherited
public elementNS ( $lname, $namespace = null )
    public function elementNS($lname, $namespace = null)
    {
        $this->findAnyElement = false;
        $found = new \SplObjectStorage();
        $matches = $this->candidateList();
        foreach ($matches as $item) {
            // Looking up NS URI only works if the XMLNS attributes are declared
            // at a level equal to or above the searching doc. Normalizing a doc
            // should fix this, but it doesn't. So we have to use a fallback
            // detection scheme which basically searches by lname and then
            // does a post hoc check on the tagname.
            //$nsuri = $item->lookupNamespaceURI($namespace);
            $nsuri = $this->dom->lookupNamespaceURI($namespace);
            // XXX: Presumably the base item needs to be checked. Spec isn't
            // too clear, but there are three possibilities:
            // - base should always be checked (what we do here)
            // - base should never be checked (only children)
            // - base should only be checked if it is the root node
            if ($item instanceof \DOMNode && $item->namespaceURI == $nsuri && $lname == $item->localName) {
                $found->attach($item);
            }
            if (!empty($nsuri)) {
                $nl = $item->getElementsByTagNameNS($nsuri, $lname);
                // If something is found, merge them:
                //if (!empty($nl)) $found = array_merge($found, $this->nodeListToArray($nl));
                if (!empty($nl)) {
                    $this->attachNodeList($nl, $found);
                }
            } else {
                //$nl = $item->getElementsByTagName($namespace . ':' . $lname);
                $nl = $item->getElementsByTagName($lname);
                $tagname = $namespace . ':' . $lname;
                $nsmatches = array();
                foreach ($nl as $node) {
                    if ($node->tagName == $tagname) {
                        //$nsmatches[] = $node;
                        $found->attach($node);
                    }
                }
                // If something is found, merge them:
                //if (!empty($nsmatches)) $found = array_merge($found, $nsmatches);
            }
        }
        $this->matches = $found;
    }