Jump to content

[SOLVED] simpleXML Errors. Not sure what the cause is...


Alex-Grim

Recommended Posts

The path should be correct, so i doubts that's the problem, and the file is a valid rss feed:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<rss version="2.0">
<channel>

<title>LinuxIntro.com</title>
<description>A great place to learn Linux! Featuring Video lessons, examples, and more</description>
<link>http://LinuxIntro.com/</link>

<language>en-us</language>
<webMaster>[email protected]</webMaster>

<item>
<title>Dark Elysium's website's are down for a while</title>
<description>The both AlexGrim.com and GrimMusic.com are down for a while.</description>
<link>http://GrimMusic.com</link> 
<guid isPermaLink="true">http://GrimMusic.com</guid>
</item>

<item>
<title>Register as an official Linux user!</title>
<description>If you use linux, you can add yourself to the registered user db.</description>
<link>http://counter.li.org</link>
<guid isPermaLink="true">http://counter.li.org</guid>
</item>

</channel>
</rss>

 

Here's my error:

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 3: parser error : Start tag expected, '<' not found in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php on line 12

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php on line 12

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php on line 12

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php:12 Stack trace: #0 /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php(12): SimpleXMLElement->__construct('??') #1 {main} thrown in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php on line 12

 

Thanx in advance, i'd really like to fix this one.

I changed my code and amended this:

if (file_exists('NewArticles.rss')) {
    $xmlFile = simplexml_load_file('NewArticles.rss');

    print_r($xml);
} else {
    exit('Failed to open test.xml.');
}

And it's finding the file, it just can't read it...

Changed code to this...

$xml = new SimpleXMLElement("NewArticles.rss",null,true);
$item = $xml->addChild("item");
$item->addChild("title", $_POST['title']);
$item->addChild("description", substr($_POST['contents'],0,666));
$item->addChild("link","http://LinuxIntro.com?con=".$_POST['name']);
$item->addChild("guid","http://LinuxIntro.com?con=".$_POST['name']);
echo $xmlFile->asXML();

And now  i'm only getting this error:

Fatal error: Call to a member function asXML() on a non-object in /var/www/html/Alex/LinuxIntro/terminal/CreateContent2.php on line 26

I fixed it, here's the resulting code:

$xml = new SimpleXMLElement("../rss/NewArticles.rss",null,true);
$item = $xml->channel[0]->addChild("item");
$item->addChild("title", $_POST['title']);
$item->addChild("description", substr($_POST['contents'],0,666));
$item->addChild("link","http://LinuxIntro.com?con=".$_POST['name']);
$item->addChild("guid","http://LinuxIntro.com?con=".$_POST['name']);
echo $xml->asXML();
//fwrite($,$);

Btw, i love your avatar.

 

Now to work on getting it to write to my rss file...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.