Edit report at http://bugs.php.net/bug.php?id=52751&edit=1
ID: 52751 User updated by: ivan dot enderlin at hoa-project dot net Reported by: ivan dot enderlin at hoa-project dot net Summary: XPath processing-instruction() function is not supported. Status: Open Type: Feature/Change Request -Package: *XML functions +Package: SimpleXML related Operating System: All PHP Version: Irrelevant Block user comment: N New Comment: Change bug's package. Previous Comments: ------------------------------------------------------------------------ [2010-08-31 11:52:08] ivan dot enderlin at hoa-project dot net I forget to notice that DOMXPath support this function. If we take the first code example: $doc = dom_import_simplexml($sxe)->ownerDocument; $xpath = new DOMXPath($doc); $e = $xpath->query('//processing-instruction(\'baz\')'); var_dump($e, $e->length, $e->item(0)->data); It will output: object(DOMNodeList)#8 (0) { } int(1) string(11) "href="ftw" " That's what we expected! But I think that SimpleXML does not simply support PI. Maybe you noticed that when outputing //bar, in the 2 offset, we have âbazâ. Well, try to use it: $handle = $sxe->xpath('//bar'); var_dump( dom_import_simplexml($handle[2]) ->childNodes ->item(0) ->data ); It will output: string(11) "href="ftw" " We must use the DOM API to reach PI data. Conclusion: ⢠processing-instruction() works with DOMXpath, not with SimpleXML. ⢠PIs appear in the DOM and the SimpleXML tree. ⢠PIs are usable only with the DOM API. ------------------------------------------------------------------------ [2010-08-31 11:24:13] ivan dot enderlin at hoa-project dot net Description: ------------ SimpleXML misses a XPath function which is processing-instruction(). This last one enables to reach/select PIs along the XML document. Test script: --------------- <?php $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n" . '<foo>' . "\n" . ' <bar>Gordon</bar>' . "\n" . ' <bar><![CDATA[Gordon]]></bar>' . "\n" . ' <bar><?baz href="ftw" ?></bar>' . "\n" . '</foo>'; $sxe = simplexml_load_string($xml); var_dump( $sxe->xpath('//bar') ); var_dump( $sxe->xpath('//processing-instruction(\'baz\')') ); Expected result: ---------------- //bar array(3) { [0]=> object(SimpleXMLElement)#2 (1) { [0]=> string(6) "Gordon" } [1]=> object(SimpleXMLElement)#3 (0) { } [2]=> object(SimpleXMLElement)#4 (1) { ["baz"]=> object(SimpleXMLElement)#5 (0) { } } } //processing-instruction('baz') array(1) { [2]=> object(SimpleXMLElement)#6 (1) { ⦠} } Actual result: -------------- //bar array(3) { [0]=> object(SimpleXMLElement)#2 (1) { [0]=> string(6) "Gordon" } [1]=> object(SimpleXMLElement)#3 (0) { } [2]=> object(SimpleXMLElement)#4 (1) { ["baz"]=> object(SimpleXMLElement)#5 (0) { } } } //processing-instruction('baz') array(0) { } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52751&edit=1