public function testXHTMLXLink() { $dom = new BetterDOMDocument($this->xml); $this->assertEquals($this->html, $dom->asHTML(FALSE, array('xlink' => TRUE))); }
public function testFirstTitle() { $dom = new BetterDOMDocument($this->xml); $this->assertEquals("Test Title", $dom->xpathSingle('.//hwsearch:highwire-title', "//hwsearch:result[@index='1']")->nodeValue); }
/** * Create an DOMElement from XML and attach it to the DOMDocument * * Note that this does not place it anywhere in the dom tree, it merely imports it. * * @param string $xml * XML string to import */ function createElementFromXML($xml) { // To make thing easy and make sure namespaces work properly, we add the root namespace delcarations if it is not declared $namespaces = $this->ns; $xml = preg_replace_callback('/<[^\\?^!].+?>/s', function ($root_match) use($namespaces) { preg_match('/<([^ <>]+)[\\d\\s]?.*?>/s', $root_match[0], $root_tag); $new_root = $root_tag[1]; if (strpos($new_root, ':')) { $parts = explode(':', $new_root); $prefix = $parts[0]; if (isset($namespaces[$prefix])) { if (!strpos($root_match[0], "xmlns:{$prefix}")) { $new_root .= " xmlns:{$prefix}='" . $namespaces[$prefix] . "'"; } } } return str_replace($root_tag[1], $new_root, $root_match[0]); }, $xml, 1); $dom = new BetterDOMDocument($xml, $this->auto_ns); if (!$dom->documentElement) { trigger_error('BetterDomDocument Error: Invalid XML: ' . $xml); } $element = $dom->documentElement; // Merge the namespaces foreach ($dom->getNamespaces() as $prefix => $url) { $this->registerNamespace($prefix, $url); } return $this->importNode($element, true); }