[英]XML Parsing Error… No Element Found
我有一个脚本生成一个XML文档,该文档突然停止工作。 当我运行它时,出现此错误:
XML解析错误:找不到元素位置: http : //www.mydomain.com/indeed-general-xml/行号1,列1:
这是生成节点结构的代码和循环:
header('Content-Type: text/xml');
//create DOMDocument object and set char encoding
$doc = new DOMDocument('1.0','utf-8');
$doc->formatOutput = true;
//root element
$r = $doc->createElement( "source" );
//append root element to our document
$doc->appendChild( $r );
$publisher = $doc->createElement("publisher");
$publisher->appendChild($doc->createTextNode("mydomain.com"));
$r->appendChild($publisher);
$publisherurl = $doc->createElement("publisherurl");
$publisherurl->appendChild($doc->createTextNode("http://mydomain.com"));
$r->appendChild($publisherurl);
$job = array();
//set args for query
$args = array(
'post_author' => -1,
'post_type' => 'job_listing',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
);
//run query
$feed_jobs = new WP_Query($args);while($feed_jobs->have_posts()) : $feed_jobs->the_post();
$b = $doc->createElement( "job" );
//begin loop
(while $feed_jobs->have_posts()) : $feed_jobs->the_post();
$title = $doc->createElement("title");
$title->appendChild($doc->createCDATASection( $post->post_title));
$b->appendChild( $title );
$company_name = "Sample Company Name";
$company = $doc->createElement("company");
$company->appendChild($doc->createCDATASection($company_name));
$b->appendChild($company);
$date = $doc->createElement("date");
$date->appendChild($doc->createCDATASection($post->post_date));
$b->appendChild($date);
$referencenumber = $doc->createElement("referencenumber");
$referencenumber->appendChild($doc->createCDATASection($post->ID));
$b->appendChild($referencenumber);
$url = $doc->createElement("url");
$url->appendChild($doc->createCDATASection($post->guid));
$b->appendChild($url);
$description = $doc->createElement("description");
$description = createCDATASection($post->post_content);
$description->appendChild($description);
$b->appendChild($description);
//query postmeta table for city and state// then parse it into an array
$location = get_post_meta($post->ID,'geo_address',true);
$location = explode(',',$location);
$city = $doc->createElement("city");
$city->appendChild($doc->createCDATASection($location[0]));
$b->appendChild($city);
$state = $doc->createElement("state");
$state->appendChild($doc->createCDATASection($location[1]));
$b->appendChild($state);
$r->appendChild( $b );
endwhile;
我认为标题中的空行不会有问题,因为我有一个运行完美的脚本,唯一的不同是从数据库中提取了用户数据。 而且当我换出查询时,损坏的脚本也不会运行。
这个错误使我发疯。 非常感谢您的帮助。
编辑:这是我被要求的预期输出的示例
<source>
<publisher>mydomain.com</publisher>
<publisherurl>http://mydomain.com</publisherurl>
<job>
<company_name>ABC Company</company_name>
<date>3-4-2011 10:54</date>
<referencenumber>1234</referencenumber>
<url>http://www.mydomain.com/extension</url>
<description>Block of of content, likely ranging several thousand characters. HTML tags included, but should be sanitized by use of createCDATASection() method</description>
<city>Oakland</city>
<state>California</state>
</job>
</source>
$description = $doc->createElement("description");
$description = createCDATASection($post->post_content);
$description->appendChild($description);
???
您是要给自己添加一些东西吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.