【问题标题】:what does means symbol "@" in this output?此输出中的符号“@”是什么意思?
【发布时间】:2011-08-31 11:39:53
【问题描述】:
SimpleXMLElement Object(

 [ImageFormat] => SimpleXMLElement Object(

  [@attributes] => Array(

    [DimensionCategory] => small
    [Title] => extra  
  )

  [URL] => link..
 )
)

【问题讨论】:

  • 你需要说明你从哪里得到的输出!
  • 好的!这是 print_r() 函数生成的输出。
  • 也许只是班级成员的名字……
  • 为什么会员“URL”没有得到符号“@”?
  • URL 是一个元素节点,而 @attributes ... 名字已经告诉你的是属性

标签: php simplexml


【解决方案1】:

@attributes由此派生

<ImageFormat DimensionCategory="small" Title="extra">
  <URL />
</ImageFormat>

换句话说,是给定元素的属性

see this

【讨论】:

  • 但符号“@”是否表示“ImageFormat 的属性”?
【解决方案2】:

作为knittl stated,它只是一个成员名。注意:访问 SimpleXML 节点中的属性,而不是这样做:

echo $xml->ImageFormat->{'@attributes'}['Title'];

一个会做的:

echo $xml->ImageFormat['Title'];

【讨论】:

    【解决方案3】:

    只是会员名的一部分:

    echo $xml->ImageFormat->{'@attributes'}['Title'];
    

    您应该使用SimpleXMLElement 类的attributes() 方法来访问XML 元素的属性。

    【讨论】:

      猜你喜欢
      • 2010-09-29
      • 2011-04-18
      • 2012-02-29
      • 1970-01-01
      • 2011-04-07
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 2022-12-22
      相关资源
      最近更新 更多