public function testXpath() { if (!extension_loaded('xsl')) { $this->markTestSkipped(); } $doc = new DOMDocument(); $doc->loadXML('<data><foo id="1"><baz id="2" value="foo"></baz></foo></data>'); $result = $doc->xPath('//*/@id'); $this->assertInstanceOf('DOMNodeList', $result); $this->assertSame(2, $result->length); $result = $doc->firstChild->xPath('//foo'); $this->assertInstanceOf('DOMNodeList', $result); $this->assertSame(1, $result->length); }
/** * Append a childelement from a well formed xml string. * * @param string $xml a well formed xml string * @access public * @return void */ public function appendChildFromXmlString($xml) { $dom = new DOMDocument(); $dom->loadXML($xml); $element = simplexml_import_dom($dom); $this->appendChildNode($element); }
public function toArray(DOMDocument $dom, $checkPrefixes = false) { $this->checkPrefixes = $checkPrefixes; $dom->normalizeDocument(); $xmlObj = simplexml_import_dom($dom, '\\Thapp\\XmlBuilder\\Dom\\SimpleXMLElement'); $namespaces = $xmlObj->getNamespaces(); $root = key($namespaces) !== '' ? $this->prefixKey(key($namespaces), $xmlObj->getName()) : $xmlObj->getName(); $data = $this->parseXML($xmlObj, $namespaces); return array($root => $data); }