在我所看到的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