php - Why does node() XPath node type test return duplicates when used with SimpleXMLElement? -


i used examle xml document practice. , don't understand node() function in xpath. example if write:

$catalog = new simplexmlelement("cd.xml",null,true); $elms = $catalog->xpath("//cd[23]/node()");  print_r($elms); 

result is:

array (     [0] => simplexmlelement object         (             [@attributes] => array                 (                     [id] => 24                     [genre] => soul                 )              [title] => dock of bay             [artist] => otis redding             [country] => usa             [company] => stax records             [price] => 7.90             [year] => 1968         )      [1] => simplexmlelement object         (             [0] => dock of bay         )      [2] => simplexmlelement object         (             [@attributes] => array                 (                     [id] => 24                     [genre] => soul                 )              [title] => dock of bay             [artist] => otis redding             [country] => usa             [company] => stax records             [price] => 7.90             [year] => 1968         ) ... 

and on, repeating cd[23] element after every child element. tried many variations of this, , duplicates in way. don't understand why that?

i tried editing xml document removing new lines , spaces, there no text nodes in between elements, , result without duplicates. case way of xpath() method represent text nodes?

i think part of problem results simplification simplexml involves, xpath method returns array of simplexmlelements , path using node() select kind of child node of cd[23] in pure xpath mapping node list or set containing text nodes , element nodes, seems designers of api php in case of text node selected return parent element text node child of cd[23] selected same parent element returned in array. might want go cd[23]/* select child elements.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -