我有一个xml obj,例如:
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
)
)
如何导航到[text]和[响应]?问题是$ xmltxt->结果 ->问题[1] ->@属性将行不通。可能是 @符号是我如何绕过此的原因?
使用属性()访问XML属性
echo $xmlTxt->results->question[1]->attributes()->text;
如果要使用特殊字符访问对象属性,请使用{}
,例如
$xmlTxt->results->question[1]->{'@attributes'}