从SimpleXMLElement对象中增强单个属性


Accesing individual property from SimpleXMLElement Object

在将其标记为重复之前,请注意,我找不到特定案例的答案。

我有一个SOAP XML响应,我使用将其存储在一个对象中

$resultObj=SimpleXML_Load_String($xml);

如果我打印对象,我得到:

SimpleXMLElement Object
(
    [soap_Body] => SimpleXMLElement Object
        (
            [SubmitNewApplicationShortResponse] => SimpleXMLElement Object
                (
                    [SubmitNewApplicationShortResult] => SimpleXMLElement Object
                        (
                            [Errors] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [IsError] => true
                                        )
                                    [ErrorDetails] => SimpleXMLElement Object
                                        (
                                            [ErrorDetail] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [Code] => 209
                                                            [Message] => Client Reference already exists.
                                                        )
                                                )
                                        )
                                )
                            [Token] => 00000000-0000-0000-0000-000000000000
                            [ProposalID] => 0
                        )
                )
        )
)

我可以使用访问令牌

$token  = (string)$resultObj->soap_Body->SubmitNewApplicationShortResponse->SubmitNewApplicationShortResult->Token

但是,我不知道如何访问"代码"answers"消息"属性。"@属性"是什么?

EDIT:我的代码中似乎有一个错误,在SimpleXML对象中应该忽略@attributes。这是有效的,如@mark91:所示

print_r( (string) $resultObj->soap_Body->SubmitNewApplicationShortResponse->SubmitNewApplicationShortResult->Errors->ErrorDetails->ErrorDetail["Code"] );

你试过这样做吗?

 $resultObj->SubmitNewApplicationResponse->SubmitNewApplicationResult->Errors->ErrorDetails->ErrorDetail["Code"];