Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP File Handling with PHP Parsing Specific Formats Writing XML

Seth Johnson
Seth Johnson
15,199 Points

"simplexml_load_file" warning

I'm working on this practice project on my local machine, just running a localhost through my terminal on my macbook. I've used "chmod" to adjust the permissions. Every time I try to run the "write_xml" script, I get this warning:

Warning: simplexml_load_file(): I/O warning : failed to load external entity "..data/xml/"

aaaaand, I'm not really sure what's happening. Here's my code:


$file = '..data/xml/' . filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
if ($xml = simplexml_load_file($file)) {
  $item = $xml->channel->addChild('item');
  $item->addChild('title', filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING));
  $item->addChild('link', filter_input(INPUT_POST, 'link', FILTER_SANITIZE_STRING));
  $date = new DateTime(filter_input(INPUT_POST, 'pubDate',
  $item->addChild('pubDate', $date->format('D, d M Y H:i:s +0000'));
  $item->addChild('description', filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING));

If anyone can point me in the right direction, it would be most appreciated. Thanks!

1 Answer

Hi Seth,

It looks like your variable $file has an incorrect start to it. It should be $file = '../data/xml/' it looks like you missed a slash.