【问题标题】:Read XML in PHP [closed]在 PHP 中读取 XML [关闭]
【发布时间】:2012-10-16 13:43:26
【问题描述】:

我正在尝试使用 simplexml_load_file 读取 XML。以下是我的 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>

直到&lt;/map_style&gt;,我都可以阅读XML。但是,只要我添加:

<!------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 文件上方。

【问题讨论】:

  • 但是,只要我添加 .... 什么?
  • 他用一个以前没有的来源完成了这个问题!

标签: php xml-parsing


【解决方案1】:

您的 XML 似乎无效。 XML 总是需要一个根节点!在您的示例中,有三个...

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多