4
即 - 我想返回一个字符串 “黄” 使用类似XPath表达式 “//香蕉/ @色” 和下面的示例XML ...我可以使用SimpleXML和Xpath直接选择元素属性吗?
<fruits>
<kiwi color="green" texture="hairy"/>
<banana color="yellow" texture="waxy"/>
</fruits>
$fruits = simplexml_load_string(
'<fruits>
<kiwi color="green" texture="hairy"/>
<banana color="yellow" texture="waxy"/>
</fruits>');
print_r($fruits->xpath('//banana/@color'));
产生
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[color] => yellow
)
)
)
而我宁愿像...
Array
(
[0] => SimpleXMLElement Object
(
[0] => yellow
)
)
...所以我不需要写一个特殊情况到我正在写的应用程序。
非常感谢! :)