Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP File Handling with PHP Parsing Specific Formats Writing XML

Seth Johnson
Seth Johnson
14,886 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:

<?php

$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',
  FILTER_SANITIZE_STRING));
  $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

Broderick Lemke
Broderick Lemke
13,483 Points

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.