homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

trying to parse XML file
trying to parse XML file

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

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



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

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


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

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.


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

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");

But still nothing?


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

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved