2016-12-23 44 views
-2
顯示XML數據

我有這樣使用PHP

<?xml version="1.0" encoding="utf-8"?> 
<Search> 
<Pages Count="40"> 
<Page Number="1">Data in page1</Page> 
<Page Number="2">Data in page2</Page> 
<Page Number="3">Data in page3</Page> 
<Page Number="4">Data in page4</Page> 
<Page Number="5">Data in page5</Page> 
</Pages> 
</Search> 

如何顯示在使用PHP 我的XML文件中的數據這是我的代碼來顯示XML數據,但仍錯誤顯示頁數據的數據pagenumber.xml數據

<?php 
$dataxml = simplexml_load_file('pagenumber.xml'); 

foreach($dataxml->Pages as $buku) 
{ 
    echo "Pages count: ".$buku['Count']."<br>"; 
    echo "Data in page 1: --> i don't know how to show the data 
    echo "Data in page 2: --> i don't know how to show the data 
    echo "Data in page 3: --> i don't know how to show the data 
    echo "Data in page 4: --> i don't know how to show the data 
    echo "Data in page 5: --> i don't know how to show the data 
} 
?> 

感謝;)

回答

0
<?php 
$dataxml = simplexml_load_file('pagenumber.xml'); 

foreach($dataxml->Pages as $buku) 
{ 
    echo "Pages count: ".$buku['Count']."<br/>"; 
    foreach($buku->Page as $page) 
    { 
     echo "Data in page "; 
     echo $page['Number']; 
     echo ": --> "; 
     echo $page; 
     echo "<br/>"; 
    } 

?> 
+0

非常感謝,它的作品;) – Rivai

0
<?php 
$dataxml = simplexml_load_file('pagenumber.xml'); 
foreach($dataxml->Pages as $buku) 
{ 
    echo $buku->Page[0]; 
    echo $buku->Page[2]; 
    echo $buku->Page[3]; 
    echo $buku->Page[4]; 
    echo $buku->Page[5]; 
} 
?>