2012-10-16 78 views
-2

我正在尝试使用simplexml_load_file读取XML。以下是我的XML:在PHP中阅读XML

<map_style> 
    <background_color>FFFFFF</background_color>   

    <state_color>c5d577</state_color> 
    <label_color>212121</label_color> 

    <state_hover_color>AECE13</state_hover_color> 
    <label_hover_color>FFFFFF</label_hover_color> 

    <state_inactive_color>dbe99c</state_inactive_color> 
    <label_inactive_color>212121</label_inactive_color> 

    <stroke_color>AECE13</stroke_color> 

    <lake_color>ffffff</lake_color> 
    <lake_stroke_color>ffffff</lake_stroke_color> 

    <other_color>FFFFFF</other_color> 
    <other_stroke_color>FFFFFF</other_stroke_color> 
</map_style> 

<!------for map on home page----------------> 
<mapstyle_home mapOutlineColor="c2da78" mapRollOverColor="AECE13" mapGradientColor="AECE13"></mapstyle_home> 

<!------for featured properties settings----------------> 
<featured_property_style> 
    <layout width="203" height="182" background="#FFFFFF" imageBackground="#aec565" showGrid="1" autoPlayDefault="1" /> 
    <buttons navigationDots="1" playPause="1" /> 
    <text option="1" /> 
<featured_property_style> 

我可以读取XML直到</map_style>。但是,只要我补充:

<!------for map on home page----------------> 
<mapstyle_home mapOutlineColor="c2da78" mapRollOverColor="AECE13" mapGradientColor="AECE13"></mapstyle_home> 

<!------for featured properties settings----------------> 
<featured_property_style> 
    <layout width="203" height="182" background="#FFFFFF" imageBackground="#aec565" showGrid="1" autoPlayDefault="1" /> 
    <buttons navigationDots="1" playPause="1" /> 
    <text option="1" /> 
<featured_property_style> 

并尝试读取XML,然后它会给出错误。

以下是我的代码:

$xml = simplexml_load_file($strCurlUrl); 

    //$xml = new SimpleXMLElement($strCurlUrl); 

    //echo $xml->getName() . "<br />"; 
    $this->m_arrXml = array(); 
    foreach($xml->children() as $child) 
    { 
     //echo $child->getName() . ": " . $child . "<br />"; 
     $this->m_arrXml[$child->getName()] = $child; 

    } 

其中$strCurlUrl高于XML文件。

+2

但是,只要我加....什么? – Teejay

+0

那么,什么是错误? – feeela

+0

他用一段前所未有的来源完成了这个问题! – Teejay

回答

5

它看起来像你的XML是无效的。 XML总是只需要一个根节点!在你的例子中有三个......