dongyan3018 2012-10-16 13:43
浏览 16

用PHP读取XML [关闭]

I am trying to read XML using simplexml_load_file. Following is my 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>

I can read XML till </map_style>. However, as soon as I add:

<!------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>

And try to read XML then it gives an error.

Following is my code:

$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;

    }

where $strCurlUrl is above xml file.

  • 写回答

1条回答 默认 最新

  • doufangxian4985 2012-10-16 13:47
    关注

    It looks like your XML is invalid. XML always requires exactly one Root-Node! In your example there are three of them...

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真