我从网站的早期版本(它是一个自定义 CMS)中获得了数据,并希望将其设置为可以将其导入我的 Wordpress 网站的状态。
这就是我正在做的事情 - http://www.teamworksdesign.com/clients/ciw/datatest/index.php。如果向下滚动到第 187 行,数据开始失败(应该有一条红色消息)并显示以下错误消息:
致命错误:在 /home/teamwork/public_html/clients/ciw/datatest/index.php:132 中未捕获的异常“异常”和消息“字符串无法解析为 XML” 堆栈跟踪:#0 /home/teamwork/public_html/客户端/ciw/datatest/index.php(132): SimpleXMLElement->__construct('
谁能看到问题是什么以及如何解决?
这就是我输出日期的方式:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
ini_set('memory_limit','1024M');
ini_set('max_execution_time', 500); //300 seconds = 5 minutes
echo "<br />memory_limit: " . ini_get('memory_limit') . "<br /><br />";
echo "<br />max_execution_time: " . ini_get('max_execution_time') . "<br /><br />";
libxml_use_internal_errors(true);
$z = new XMLReader;
$z->open('dbo_Content.xml');
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
// move to the first <product /> node
while ($z->read() && $z->name !== 'dbo_Content');
$c = 0;
// now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'dbo_Content')
{
if($c < 201) {
// either one should work
$node = simplexml_import_dom($doc->importNode($z->expand(), true));
if($node->ClassId == 'policydocument') {
$c++;
echo "<h1>Row: $c</h1>";
echo "<pre>";
echo htmlentities($node->XML) . "<br /><br /><br /><b>*******</b><br /><br /><br />";
echo "</pre>";
try{
$xmlObject = new SimpleXMLElement($node->XML);
foreach ($xmlObject->fields[0]->field as $field) {
switch((string) $field['name']) {
case 'parentId':
echo "<b>PARENT ID: </b> " . $field->value . "<br />";
break;
case 'title':
echo "<b>TITLE: </b> " . $field->value . "<br />";
break;
case 'summary':
echo "<b>SUMMARY: </b> " . $field->value . "<br />";
break;
case 'body':
echo "<b>BODY:</b> " . $field->value . "<br />";
break;
case 'published':
echo "<b>PUBLISHED:</b> " . $field->value . "<br />";
break;
}
}
echo '<br /><h2 style="color:green;">Success on node: '.$node->ContentId.'</h2><hr /><br />';
} catch (Exception $e){
echo '<h2 style="color:red;">Failed on node: '.$node->ContentId.'</h2>';
}
}
// go to next <product />
$z->next('dbo_Content');
}
} ?>
</body>
</html>