Php 为什么字符串周围的大括号不能输出正确的SimpleXML结果?

Php 为什么字符串周围的大括号不能输出正确的SimpleXML结果?,php,xml,oop,simplexml,curly-braces,Php,Xml,Oop,Simplexml,Curly Braces,我从一个API获取数据,该API返回如下任务列表: <tasks> <task> <id type="integer">937510</id> <external-id nil="true"> <description>needs to be italic in the 2nd line of copy in this paragraph</description> <

我从一个API获取数据,该API返回如下任务列表:

<tasks>
  <task>
    <id type="integer">937510</id>
    <external-id nil="true">
      <description>needs to be italic in the 2nd line of copy in this paragraph</description>
    </external-id>
  </task>
</tasks>
但是,我收到的输出如下。即使我用大括号和引号将外部id括起来,也无法访问它

<h2>280095</h2>
<h2></h2>
如果我将'external id'保存到$external\u id这样的变量中,并使用->任务[0]->$external\u id访问它,则会得到相同的结果

我需要做什么才能访问外部id节点内的数据


编辑:事实证明,当SimpleXml解析XML时,它将description设置为external-id的子级。将查询更新为task[0]->description解决了这个问题。谢谢,mario。

在$tasks\u对象中表示什么?我们刚刚尝试了打印示例XML,它显示正确。在输出中,ID值不同。您确定描述不是空的吗?该ID是项目ID,而不是任务ID。出于某种原因,simplexml正在将描述解析为外部ID的同级而不是子级。我不确定为什么会发生这种情况,但更改我的查询解决了问题。这对我来说很好。有趣-必须是导致转换中异常行为的实际任务数据集的工件。
<h2>280095</h2>
<h2></h2>