在我所看到的XML结构的simplexml的所有例子是这样的:的SimpleXML与多个标签
<examples>
<example>
</example>
<example>
</example>
<example>
</example>
</examples>
但是我处理XML形式:
<examples>
<example>
</example>
<example>
</example>
<example>
</example>
</examples>
<app>
<appdata>
<error>
<Details>
<ErrorCode>101</ErrorCode>
<ErrorDescription>Invalid Username and Password</ErrorDescription>
<ErrorSeverity>3</ErrorSeverity>
<ErrorSource />
<ErrorDetails />
</Details>
</error>
<items>
<item>
</item>
<item>
</item>
</items>
</appdata>
</app>
我会喜欢跳过示例的东西,并直接进入应用程序标记,并检查错误错误码是否存在,如果不存在,请转到items数组并循环。
我处理这个电流的方法是:
$items = new SimpleXMLElement($xml_response);
foreach($items as $item){
//in here I check the presence of the object properties
}
有没有更好的办法?问题是xml结构有时会改变顺序,所以我希望能够直接转到xml的特定部分。
这不是你正在处理的XML,除非它有共同的根节点。 – dfsq 2014-10-22 11:04:41