这是我迄今为止尝试过的,它给了我一堆我不想要的东西(浏览器输出见底部):
// transform to Simple XML
$xml = new SimpleXMLElement($results);
// find category names
$xml = $xml->xpath('params/param/value/array/data/value/struct/member/value/string');
print_r($xml);
这是 XML,我需要获取所有 categoryName 节点:
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<array><data>
<value><struct>
<member><name>categoryId</name><value><string>7</string></value></member>
<member><name>parentId</name><value><string>0</string></value></member>
<member><name>description</name><value><string>@MyCat000egory</string></value></member>
<member><name>categoryDescription</name><value><string></string></value></member>
<member><name>categoryName</name><value><string>@MyCat000egory</string></value></member>
<member><name>htmlUrl</name><value><string>http://en.webacceleration.net/?cat=7</string></value></member>
<member><name>rssUrl</name><value><string>http://en.webacceleration.net/?feed=rss2&amp;cat=7</string></value></member>
</struct></value>
<value><struct>
<member><name>categoryId</name><value><string>6</string></value></member>
<member><name>parentId</name><value><string>0</string></value></member>
<member><name>description</name><value><string>this is the category</string></value></member>
<member><name>categoryDescription</name><value><string></string></value></member>
<member><name>categoryName</name><value><string>this is the category</string></value></member>
<member><name>htmlUrl</name><value><string>http://en.webacceleration.net/?cat=6</string> </value></member>
<member><name>rssUrl</name><value><string>http://en.webacceleration.net/?feed=rss2&amp;cat=6</string></value></member>
</struct></value>
<value><struct>
<member><name>categoryId</name><value><string>1</string></value></member>
<member><name>parentId</name><value><string>0</string></value></member>
<member><name>description</name><value><string>Uncategorized</string></value></member>
<member><name>categoryDescription</name><value><string></string></value></member>
<member><name>categoryName</name><value><string>Uncategorized</string></value></member>
<member><name>htmlUrl</name><value><string>http://en.webacceleration.net/?cat=1</string></value></member>
<member><name>rssUrl</name><value><string>http://en.webacceleration.net/?feed=rss2&amp;cat=1</string></value></member>
</struct></value>
</data></array>
</value>
</param>
</params>
</methodResponse>
这是浏览器输出:
Array ( [0] => SimpleXMLElement Object ( [0] => 7 ) [1] => SimpleXMLElement Object ( [0] => 0 ) [2] => SimpleXMLElement Object ( [0] => @MyCat000egory ) [3] => SimpleXMLElement Object ( ) [4] => SimpleXMLElement Object ( [0] => @MyCat000egory ) [5] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?cat=7 ) [6] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?feed=rss2&cat=7 ) [7] => SimpleXMLElement Object ( [0] => 6 ) [8] => SimpleXMLElement Object ( [0] => 0 ) [9] => SimpleXMLElement Object ( [0] => this is the category ) [10] => SimpleXMLElement Object ( ) [11] => SimpleXMLElement Object ( [0] => this is the category ) [12] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?cat=6 ) [13] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?feed=rss2&cat=6 ) [14] => SimpleXMLElement Object ( [0] => 1 ) [15] => SimpleXMLElement Object ( [0] => 0 ) [16] => SimpleXMLElement Object ( [0] => Uncategorized ) [17] => SimpleXMLElement Object ( ) [18] => SimpleXMLElement Object ( [0] => Uncategorized ) [19] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?cat=1 ) [20] => SimpleXMLElement Object ( [0] => http://en.webacceleration.net/?feed=rss2&cat=1 ) )