/** * Extracts DOMNodeList from any kind of DOM objects * * @param $DOMObject * @param \DOMElement|\DOMNode|\DOMNodeList|\DomDocument $DOMObject * @throws \MDA\DDU\Exception * @return \DOMNodeList */ public static function extract($DOMObject) { if ($DOMObject instanceof \DOMNodeList) { return $DOMObject; } elseif ($DOMObject instanceof \DOMDocument) { return $DOMObject->childNodes; } elseif ($DOMObject instanceof \DOMNode) { return Source\XPath::create(new Source\Pointer\XPath('.'), $DOMObject)->getData(); } throw new Exception(Exception::ERR_UNSUPPORTED_DOM_OBJECT); }
public function testXpathWithNodeNamespace() { $defaultNamespace = 'http://foo'; $nestedNamespace = 'http://bar'; $value = array('table' => array('@attr' => array('xmlns' => $defaultNamespace, 'xmlns:test' => $nestedNamespace), 'test:row' => array())); $dom = ToDOM::extract($value); $this->assertEquals('row', DOM\Source\XPath::create(new DOM\Source\Pointer\XPath('/xmlns:table/test:row', array('test' => $nestedNamespace)), $dom)->getFirstNode()->localName); }