$xml_file = 'book.xml';
$xml = simplexml_load_file($xml_file);
foreach ($xml->Area as $child)
{
foreach ($child->attributes() as $a=>$b)
{
//echo $a.'='.$b.'<br>';
}
}
foreach ($xml->Area->TvChanne as $child)
{
foreach ($child->attributes() as $a=>$b)
{
if ($a=='name')
{
//echo $a.'='.$b.'<br>';
}
}
}
foreach ($xml->Area as $child)
{
//echo $child->getName().'<br>';
foreach ($child->TvChanne as $child)
{
foreach ($child->attributes() as $a=>$b)
{

if ($b=='BTV-1')
{
foreach ($child->Guide as $child)
{
foreach ($child->attributes() as $a=>$b)
{
echo $b.' : '.$child.'<br>';
}
}
}
}
}
}

解决方案 »

  1.   

    使用PEAR,需要包 XML_Unserializer
    结果返回的是一个多维数组,和你的xml结构一样,非常好用
    $xml为你的文件内容<?php$unserializer = new XML_Unserializer(array( 
       'prependAttributes' => '_', 
       'parseAttributes' => true 
    )); $unserializer->unserialize($xml, false); 
    $responseData = @array($unserializer->getRootName()=>$unserializer->getUnserializedData()); print_r($responseData)?>
      

  2.   

    谢谢,如果我要指定获取某个<Area> 的<TvChanne>下<Guide>的数据,应该怎么设置呢?比如 ‘上海’ 的‘BTV-2’下的值列表。