开发者

How do I access XML attributes in PHP with simplexml?

Hello, I have this piece of XML:

<foo id="whatever" default="whatever">
  FOO
</foo>

How can I access attributes like id or default?

If I print_r($xml->foo) I see them, but they are prepended 开发者_如何学Pythonwith @


Use the array syntax for attributes and object syntax for child nodes:

$xml->foo['id']  // get `id` attribute on `foo` node

See the Using attributes example here: http://docs.php.net/manual/en/simplexml.examples-basic.php#example-4741

See also the attributes() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜