Recommend this page to a friend! |
RSS Writer class | > | All threads | > | Code Break in xmlwriterclass.php | > | (Un) Subscribe thread alerts |
|
Kass Wagoner - 2009-04-11 04:17:07
I seem to get a breakdown in code funtion at about line 188 in the Public functions area. Here is the code where things start to fall apart.
/* * Public functions * */ Function write(&$output) { if(strcmp($this->error,'')) return 0; if(!(IsSet($this->structure['0']))) { $this->error='XML document structure is empty'; return 0; } $output=('<?xml version="1.0" encoding="'.$this->outputencoding.'"?>'.$this->linebreak); if(strcmp($this->dtdtype,'')) Everything seems to be going okay until the ' following '<?xml version="1.0" encoding="'.$this->outputencoding.'"?>' In my editor, php code will be brown, but right at that ' it turns to black. I also get this error if I try to run the rss_example.php file in the browser: XML document must have a top level element. Error processing resource .... Any advise would be appreciated. This looks to be exactly the class I've been looking for, just need to get this issue figured out. Thanks! Kass
Manuel Lemos - 2009-04-11 04:29:06 - In reply to message 1 from Kass Wagoner
This does not seem to be a PHP problem. Maybe you are not setting the correct DTD type.
Can you show a small XML sample document that is generated when you run that script?
Kass Wagoner - 2009-04-11 05:29:37 - In reply to message 2 from Manuel Lemos
Manuel,
Thanks for your help! Actually when I try to run the rss_example.php file, I get the before mentioned error. I don't think it is the code per se... but the way it is being interpreted. It's like it can't get past this line in the xmlwriterclass.php file: $output=('<?xml version="1.0" encoding="'.$this->outputencoding.'"?>' Like it thinks it is getting 2 top level element directives or something. It doesn't seem to want to let the <?xml version="1.0" encoding="'.$this->outputencoding.'"?> be treated as a string, but starts to treat it as conflicting code directives or something. Basically, I just took your original files so I could learn to use them. All I did was change the rss_example.php file to reflect the new location (this is my sandbox where I try things out: /* * Specify the URL where the RSS document will be made available. */ $rss_writer_object->about='http://www.sanddollarit.com/rss/channels.xml'; and change the channel items in the rss_example.php to see what happened to the channels.xml file: /* * Then add your channel items one by one. */ $properties=array(); $properties['description']='For the Week of April 10 - April 16th..... '; $properties['link']='http://www.google.com'; $properties['title']='Title Number 1'; $properties['dc:date']='2009-09-04T00:00:00Z'; $rss_writer_object->additem($properties); $properties['description']='Description Number 2!'; $properties['link']='http://www.google.com'; $properties['title']='Title Number 2'; $properties['dc:date']='2009-09-04T00:00:00Z'; $rss_writer_object->additem($properties); This way I could see what happened and get to know how things worked. I sort of learn best by dissection. :-) Thanks again for your help. Like I said, this looks like awesome work and I'm anxious to understand it better and put it into play. Kass
Manuel Lemos - 2009-04-11 06:01:32 - In reply to message 3 from Kass Wagoner
I checked the URL http://www.sanddollarit.com/rss/channels.xml and there seems to be nothing wrong with the XML.
It seems to me that what is complaining is your browser. Which browser do you use?
Kass Wagoner - 2009-04-11 14:06:09 - In reply to message 4 from Manuel Lemos
Manuel,
Not to be stupid, but I want to understand exactly how this works. Do the rss_writer_class.php and xmlwriterclass.php files work together to take the newly changed input from the rss_example.php file to actually write over the channels.xml file on the server? So if the code worked correctly on my server, when I run the rss_example.php file in the browser, the channels.xml file will change. Is that correct? I use IE 7 and FireFox 3.0.8. I tried running rss_example.php in FF and got this error, which is a little more explicit: XML Parsing Error: no element found Location: http://www.sanddollarit.com/rss/rss_example.php Line Number 103, Column 3: ?> --^ If you run this http://www.sanddollarit.com/rss/rss_example.php in your browser, what happens? Or do I not understand how this is all inter-related and works? Thanks again for your assistance. Kass
Manuel Lemos - 2009-04-11 18:46:09 - In reply to message 5 from Kass Wagoner
No, the classes generate XML but you need to make it be served in whatever URL you want.
It seems that your Web server is not configured to treat PHP scripts as such, so instead of executing the PHP script and serve its output, it is serving the PHP script itself. If you tell you browser to view the source of the rss_example.php URL you can see the it is the script. sanddollarit.com/rss/rss_example.ph ...
Kass Wagoner - 2009-04-11 19:54:12 - In reply to message 6 from Manuel Lemos
Manuel,
Is this something I configure in my htaccess file? I googled "configure server to serve php output" and found this AddType AddType application/x-httpd-php .php I tried adding it to my htaccess file (my file below) AddHandler server-parsed .asp AddType text/html asp AddType text/xml php AddType application/x-httpd-php .php AuthName sanddollarit.com IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* I think we are getting somewhere. After adding the AddType and running rss_example.php in the browser I now get some errors, but I'm also getting some of the code from the rss_example.php file showing up. Here is the error: Warning: Cannot modify header information - headers already sent by (output started at /home/sanddoll/public_html/rss/rss_example.php:1) in /home/sanddoll/public_html/rss/rss_example.php on line 90 Warning: Cannot modify header information - headers already sent by (output started at /home/sanddoll/public_html/rss/rss_example.php:1) in /home/sanddoll/public_html/rss/rss_example.php on line 91 Starting April 24, 2009 … Some text here http://www.google.com 2009-09-04T00:00:00Z http://www.phpclasses.org/graphics/logo.gif http://www.phpclasses.org/ Repository of components and other resources for PHP developers For the Week of April 10 - April 16th..... http://www.google.com 2009-09-04T00:00:00Z Description Number 2! http://www.google.com 2009-09-04T00:00:00Z words http://www.phpclasses.org/search.html?go_search=1 Search in the PHP Classes repository Here are lines 90 and 91 90 Header('Content-Type: text/xml; charset="'.$rss_writer_object->outputencoding.'"'); 91 Header('Content-Length: '.strval(strlen($output))); Perhaps I still don't have something configured correctly on the server. Thanks for your patience and assistance. Kass
Manuel Lemos - 2009-04-11 20:50:14 - In reply to message 7 from Kass Wagoner
That means that on line one you have some data being outputted to the browser that you need to remove or else you cannot define the response headers later. Maybe it is some text or spaces before the PHP script. Just remove whatever you are outputting there.
Kass Wagoner - 2009-04-12 04:18:53 - In reply to message 8 from Manuel Lemos
Okay, that was it! Thanks! I learned that not all editors are created equal. By using Dreamweaver I can edit without creating whitespaces in the file. Now when I make adjustments to the rss_example.php file, I can run the file in the browser and see the amended file as RSS.
But, I get no change to the channels.xml file. It is listed in the rss_example.php file: /* * Specify the URL where the RSS document will be made available. */ $rss_writer_object->about='http://www.sanddollarit.com/channels.xml'; /* * Specify the URL of an optional XSL stylesheet. * This lets the document be rendered automatically in XML capable browsers. */ $rss_writer_object->stylesheet='http://www.sanddollarit.com/rss1html.xsl'; I have the xmlwriterclass.php in the same folder as the rss writer files. How do I get xml output from the rss_example.php? I tried running the xmlwriterclass.php file and I get a blank page with this as the source code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD> <BODY></BODY></HTML> |
info at phpclasses dot org
.