我有一個簡單的xml腳本,它創建了一個複雜的對象,我只想從div'grid'中獲取信息,所以抓住我使用xpath來獲取它。simplexml對象和對方陣列
$id = $sxml->xpath("//*[@id='grid_data']");
這會導致大的對象數組,這似乎是對象和數組的混合,我真的很努力地穿過它。下面是一個非常簡化的版本。有30個成員'人1'等。每個人都有一個列表,其中包含25個項目,我需要訪問/工作。 ([「li」] => array(25))
理想情況下,我需要遍歷每個成員,然後循環遍歷每個li項目,但即時通訊使用$ variable ['name'] vs $ object-> name
只是測試我嘗試了各種方法來獲取人名,我想我困惑着自己試圖圍繞對象遍歷我的頭。
echo $id[0]->div[0][p][a];
echo $id[0]['div'][0]['p']['a'];
echo $id->0->div
array(1) {
[0]=>
object(SimpleXMLElement)#3 (2) {
["@attributes"]=>
array(1) {
["id"]=>
string(9) "grid_data"
}
["div"]=>
array(35) {
[0]=>
object(SimpleXMLElement)#4 (4) {
["@attributes"]=>
array(1) {
["class"]=>
string(9) "stff_grid"
}
["p"]=>
object(SimpleXMLElement)#39 (2) {
["@attributes"]=>
array(2) {
["class"]=>
string(16) "staff"
["id"]=>
string(15) "1328"
}
["a"]=>
string(17) "Person 1"
}
["ul"]=>
object(SimpleXMLElement)#40 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(0) ""
}
["li"]=>
array(25) {
[0]=>
object(SimpleXMLElement)#42 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "00"
}
[1]=>
object(SimpleXMLElement)#43 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "01"
}
[2]=>
object(SimpleXMLElement)#44 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "02"
}
}
}
["div"]=>
object(SimpleXMLElement)#41 (1) {
["@attributes"]=>
array(1) {
["class"]=>
string(10) "left"
}
}
}
[1]=>
object(SimpleXMLElement)#5 (4) {
["@attributes"]=>
array(1) {
["class"]=>
string(9) "stff_grid"
}
["p"]=>
object(SimpleXMLElement)#41 (2) {
["@attributes"]=>
array(2) {
["class"]=>
string(16) "staff"
["id"]=>
string(15) "no_1333"
}
["a"]=>
string(11) "Person 2"
}
["ul"]=>
object(SimpleXMLElement)#40 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(0) ""
}
["li"]=>
array(25) {
[0]=>
object(SimpleXMLElement)#66 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "00"
}
[1]=>
object(SimpleXMLElement)#65 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "01"
}
[2]=>
object(SimpleXMLElement)#64 (2) {
["@attributes"]=>
array(1) {
["class"]=>
string(16) "lrge"
}
["a"]=>
string(2) "02"
}
}
}
["div"]=>
object(SimpleXMLElement)#39 (1) {
["@attributes"]=>
array(1) {
["class"]=>
string(10) "left"
}
}
}
[2]=>
object(SimpleXMLElement)#6 (1) {
["@attributes"]=>
array(1) {
["class"]=>
string(6) "spacer"
}
}
意見能否請你地方,比如引擎收錄後它的實際的XML或一部分,我想測試之前,我建議的事情。 –
好的,我會看看我是否可以將所有個人信息從團隊成員系統中刪除,以便頁面包含更多內容。 –
這將是偉大的,如果你需要從XML過濾數據只提供一個樣本與少數節點 –