2013-01-08 4 views
0

잘못된 XML 피드가 있습니다. 그것은 그들이 부러, 노드의 일부를 차단하고 나는 다음과 같은 오류 메시지가 얻을 -xml "데이터의 조기 종료"오류

Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag 

hotelDescription line 30760 in /srv/disk9/561574/www/source.xml, line: 30760 in /srv/disk9/561574/www/file.php on line 22 

Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag product line 30741 in /srv/disk9/561574/www/source.xml, line: 30760 in /srv/disk9/561574/www/file.php on line 22 

Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag products line 2 in /srv/disk9/561574/www/source.xml, line: 30760 in /srv/disk9/561574/www/file.php on line 22 
0 

내가 설정 오류 처리기가를하지만 그것도 가능한 경우, 또는 무시하는 방법을 잘 모르겠어요 요소가 오류를 일으키는 경우?

/* load the file on the DOM*/ 
$dom = new DomDocument(); 
$dom->load($filename); 

if (!$dom->load($filename)) { 
    foreach (libxml_get_errors() as $error) { 
     // handle errors here 

    } 

    libxml_clear_errors(); 
} 

도움을 주시면 감사하겠습니다.

답변

0

많은 연구를 거친 후 깨진 요소를 건너 뛸 수없는 것으로 나타났습니다. 내 상황에서

https://stackoverflow.com/a/13609656/1122187

는 말 공급 중단, 그래서 나는 마지막 깨진 요소에 도달하지 않도록, 제한을 사용하여, 단지 일정 금액을 끌어 XmlReader를 사용했다. PHP xmlreader to array

-

while ($reader->read()) 
{ 
    if (($reader->name == $element1 || $reader->name == $element2) && $reader->nodeType == XMLReader::ELEMENT) 
    { 
    $name = $reader->name; 
     if ($i == $limit) break; 
     while ($reader->read()) 
     { 
      if ($reader->nodeType == XMLReader::TEXT 
       || $reader->nodeType == XMLReader::CDATA 
       || $reader->nodeType == XMLReader::WHITESPACE 
       || $reader->nodeType == XMLReader::SIGNIFICANT_WHITESPACE) 
      { 
       $product[$i][$name] = $reader->value; 
      } 
      else if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == $element1) 
      { 
       break; 
      } 
      else if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == $element2) 
      { 
       break; 
      } 



     } 

     if($name == $element2) 
    $i++; 

    } 
} 
$reader->close(); 

위의 코드는이 링크에서 호세 베가에 신용이다