Irratic XML Feed Behavior!!!
-
I have 2 custom XML feeds I’ve built using the DOMDocument class. The code is identical, apart from the users’ content they generate. One feed pulls a custom post type from a specific user, while the other feed pulls the same post type from all other users.
They’ve both been working as designed until recently. Actually, one is still working, the feed that generates content from the single user is the one that is broke. It generates this error:
XML Parsing Error: no element found
Location: [url]https://www.mydomain/indeed-general-xml-generator/[/url]
Line Number 1, Column 1:Being the only difference between these scripts is the content the pull from the database, I’m wondering if it is the data itself that screwing up my feed. Only thing is, I’m wrapping everything the createCDATASection() method, so this should be preventing something like this from happening.
Here’s the loop that generates the XML document:
while($feed_jobs->have_posts()) : $feed_jobs->the_post(); $b = $doc->createElement( "job" ); $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;
Strange thing is, if I remove the “url” node and the “content” node the feed generates without error.
Even more strange, if I leave the the “url” node as-is and remove the “description” node as well as the “date” and “company” nodes everything generates without error again.This has been driving me crazy all night. Please help!
- The topic ‘Irratic XML Feed Behavior!!!’ is closed to new replies.