2014-10-28 09:58
浏览 120


I have written an xml-parser to read an XML-file. The XML-file is not mine so I can't change the structure. Things work great till I got to this special point. I want to read a value but I don't have a key to access this value. I marked the values (in red) in the screenshot below which I want to access.

enter image description here

When I dump the parent element (the PRAT->VALUE) I get this in return:

object(SimpleXMLElement)#31 (3) { ["@attributes"]=> array(5) { ["nr"]=> string(1) "1" ["unit"]=> string(3) "bar" ["unit_id"]=> string(4) "3103" ["vo"]=> string(0) "" ["vo_id"]=> string(0) "" } [0]=> string(2) "20" [1]=> string(1) "2" } 

As seen, at the end of the dump the values that I want to access are presented. I tried to access it like an array but that doesn't work. The values are not part of the attributes.

图片转代码服务由CSDN问答提供 功能建议

我编写了一个xml-parser来读取XML文件。 XML文件不是我的,所以我不能改变结构。 在我达到这个特殊点之前,事情很有效。 我想读取一个值,但我没有密钥来访问此值。 我在下面的截图中标记了我想要访问的值(红色)。

当我转储父元素( PRAT-> VALUE )时,我得到了回报:

  object(SimpleXMLElement)#31(3){[“@attributes”] =>  array(5){[“nr”] =>  string(1)“1”[“unit”] =>  string(3)“bar”[“unit_id”] =>  string(4)“3103”[“vo”] =>  string(0)“”[“vo_id”] =>  string(0)“”} [0] =>  string(2)“20”[1] =>  string(1)“2”} 

如图所示,在转储结束时,将显示我想要访问的值。 我试图像数组一样访问它,但这不起作用。 这些值不是属性的一部分。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxiangxie8181
    dongxiangxie8181 2014-10-28 10:12

    use (String) keyword in front of it.


    echo (String) PRAT->VALUE;
    点赞 评论