Php 简单Xml对象导航问题

Php 简单Xml对象导航问题,php,xml,Php,Xml,我有一个类似xml对象的thid: SimpleXMLElement Object ( [@attributes] => Array ( [id] => survey1_question01 [num] => 01 [text] => 1. What times will I take my 2 pills of Incivek (telaprevir) each day?

我有一个类似xml对象的thid:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [id] => survey1_question01
            [num] => 01
            [text] => 1. What times will I take my 2 pills of Incivek (telaprevir) each day?
        )

    [response] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [dose1] => 08:00 AM
                    [dose2] => 12:02 PM
                    [dose3] => 08:00 PM
                )

        )

如何导航到[文本]和[响应]?。问题是$xmlTxt->results->question[1]->@属性将不起作用。可能是@symbol是我如何绕过它的原因?

如果您想使用特殊字符访问对象属性,请使用
{}
例如

$xmlTxt->results->question[1]->{'@attributes'}
用于访问xml属性


echo$xmlTxt->results->question[1]->attributes()->text

出于某种原因,它返回一个类似于此SimpleXMLElement对象()的空对象,但问题仍然存在$xmlTxt->results->question[1]->{'@attributes'}返回空值。属性是一个数组,我可以按您所说的方式访问,但无法访问对象。@如果您编写的代码与对象转储不匹配,我将尝试
$obj->{'@attributes'}['text']
获取文本。