Welcome to WebmasterWorld Guest from 107.21.159.218

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

trying to parse XML file

trying to parse XML file

     

drooh

9:58 pm on Feb 29, 2012 (gmt 0)

5+ Year Member



not sure what Im doing wrong here, this works for just about every feed out there?

$xml = simplexml_load_file("http://alzheimersanddementia.org/current.rss");
$result = $xml->xpath("/rss/channel/item");
print_R($result); // prints nothing

The problem is I do not know what to put in the $xml->xpath("");

Any Ideas

incrediBILL

2:26 am on Mar 1, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Not sure what's going on exactly but xpath doesn't seem to like that file, makes it crash even!

For staters, it's not an RSS, it's an RDF internally, so try this and you get one result:

$xml = simplexml_load_file("http://alzheimersanddementia.org/current.rss");
$result = $xml->xpath("/rdf:RDF");
print_R($result); // prints something


However, $xml->xpath("/rdf:RDF/channel"); doesn't work for no obvious reason

incrediBILL

2:53 am on Mar 1, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I got curious so I copied their file over to my server and made an edit, changing "<rdf:RDF" and "</rdf:RDF" in the document to just "<rdf " and "</rdf>" made it all works just fine.

Easy workaround to load the file into a string first, do a string replace of "rdf:RDF" to just "rdf" and then convert it to a simple XML object.

xpath, like many PHP functions, is just a buggy bunch of ...

It's free, get what you pay for.

drooh

7:31 pm on Mar 1, 2012 (gmt 0)

5+ Year Member



For some reason, i just tried that but I dont know what you mean convert to simple XML oblect

this is what Im doing

<?
$content = file_get_contents('http://alzheimersanddementia.org/current.rss');
$content = str_replace('rdf:RDF','rdf',$content);
file_put_contents('/home/anewdaya/public_html/news.xml', $content);
?>

Then Im trying this
$xml = simplexml_load_file("/home/anewdaya/public_html/news.xml");
$result = $xml->xpath("/rdf/channel/item");
print_R($result);

But still nothing?

incrediBILL

12:08 am on Mar 2, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Try simplifying the problem, did you get '/rdf' to work? or '/rdf/channel'?

I did with the test file I made, but I chopped out a LOT of content to simplify the file.

The original file appears to be valid but it causes issues with xpath for some reason, so you need to step into it and debug the thing bit by bit until you find out the cause.

If there are any other ':'s in the xml tag names, that seems to be one show stopper.

Also make sure your code really wrote the file, sometimes PHP can't write to the public_html area without changing the directory permissions.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month