domxml解析XML文件时出错

时间:2015-07-01 12:18:31

标签: php mysql xml-parsing google-maps-markers

在php中,我正在尝试解析xml文件,而且我需要在mysql中填入以下xml文件中的“LABEL”字段,其中示例xml文件为:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<markers>
<marker ALPS="ALPS00000000" FILE="LOG_1"  time="2014-11-11 10:16:21" LABEL="09 "  />
<marker ALPS="ALPS00000000" FILE="LOG_1"  time="2014-11-11 10:16:36" LABEL="s04" />
<marker ALPS="ALPS00000000" FILE="LOG_1"  time="2014-11-11 10:17:26" LABEL="s04" />
<markers>

我正在使用xmlDOM解析xml。但我得到的错误是:  无法解析文件C:\ xampp \ tmp \ phpD0D.tmp 请帮忙

代码:

$xmlDoc = new DOMDocument(); 
$xmlDoc->load( $_FILES ['upload_file']['tmp_name'] );    

$searchNode = $xmlDoc->getElementsByTagName( "marker" ); 

foreach( $searchNode as $searchNode ) 
{ 
    $label = $searchNode->getAttribute('LABEL');
    // get other attributes here!
    if(array_key_exists($label, $this->events))
    {
      $this->events[$label]["Count"]++;
    }
    else
    {
      $this->events[$label] = array("Type" => $label,
                                                 "Host" => $this->Network,
                                                 "Count" => 1);
    }

    //echo "$label\n"; 
} 
  $xmlDoc->saveXML(); 

1 个答案:

答案 0 :(得分:0)

第一个元素中有错误的引号:

 <marker ALPS="ALPS00000000" FILE="LOG_1"  time="2014-11-11 10:16:21" LABEL="09” "  />