突然動作を停止したXML文書を生成するスクリプトがあります。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>
XML文書はどのように見えますか? –
何が好きですか?私はあなたが何かを逃したと思う:) –
はい、私は私のコメントを編集しようとしましたが、タイムアウトしました。申し訳ありませんが、ここでのコメントの書式設定は、うまく構造化されたxml文書の出力には役立ちません。コードを見ると、、、、のツリー構造が表示されます。あなたがコードから見ることができない唯一のものは、適切に開閉されたルートノードです。 –