View Full Version : XSLT functions claim my XML isn't well formed?

12-28-2003, 10:27 PM
Well, I got my XSLT functions to work (php.ini had an incorrect extensions directory stored), but now they claim my XML isn't well formed! Well, to be exact:
XML parser error 4: not well-formed (invalid token)Okay, some code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RSS Feed Parser</title>
$xh = xslt_create();
$result = xslt_process($xh, 'http://localhost/trial/rss-feed.xml', 'http://localhost/trial/rss-parser.xsl');
if (!$result) {echo "<p><strong>error:</strong> " . xslt_error($xh) . "</p>";} else echo "\" $result \"";


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="rss/channel">
<h1>RSS Feed Parser</h1>
<xsl:for-each select="item">
<h2><xsl:value-of select="title" /></h2>
<p><xsl:value-of select="description" /></p>


<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<description>Some random stuff should go here. Not sure what.</description>

<description>The second test that I'll be writing. This one comes courteous of some random bloke that I pulled off the street. Here he is, ladies and gentlemen: *Grunt* Yes, well, wasn't that interesting? I can't be bothered to write anything else, this'll do for a simple test.</description>

<title>My random trial RSS feedy thing</title>

</rss>All looks well formed to me...

12-29-2003, 03:54 AM
Just a guess here, but I've noticed when I was doing RSS feeds that if I called a file through http, I got all the http headers returned. Although the file it self does not contain them, the server will prepend them on the response.

To check this, try to open the file through http and then write the file (with a new name) somewhere. Usually the newly written file will contain the http response headers. That's probably what's causing the problem.

You may need to filter them out before you start processing the xml.

You may want to check out
this post (http://www.codingforums.com/showthread.php?s=&threadid=26012&highlight=RSS%2A).

Hope this helps.

12-29-2003, 04:30 AM
try the alternate way , I think the issues you are having are either as bcarl suggests above , OR an issue with PHP streams and how they fetch content + a bug/feature with sablatron itslef ??

anyway , this works..

$files = array(
'/_xml' => implode( '' , file( 'http://localhost/rss-feed.xml' ) ),
'/_xsl' => implode( '' , file( 'http://localhost/rss-parser.xsl' ) )

$xh = xslt_create();
xslt_set_log( $xh , true ) ;
xslt_set_log( $xh , 'e:/phpdev/www/myfile.log' ) ;
if( $whoot = xslt_process( $xh , 'arg:/_xml' , 'arg:/_xsl' , NULL , $files ) ){
echo $whoot ;
}else {
echo "<p><strong>error:</strong> " . xslt_error($xh) . "</p>" ;
xslt_free( $xh ) ;

die() ;

12-29-2003, 11:06 AM
Awesome! Thanks guys, this is a great help. :D

12-29-2003, 12:04 PM
Got ahead of myself there.
XML parser error 3: no element foundWhere:

| | relative url | absolute url | nonlocal url |
| with $_GET | no error | no error | error |
| without | no error | no error | error |
relative url is something like 'index.xml'
absolute is something like 'http://localhost/trial/index.xml'
nonlocal url is something like 'http://www.stopdesign.com/index.xml'
with $_GET means I'm imploding with implode('', $_GET['url']) and passing the url I want to parse.
Without means I type the location I want to parse into the code itself.

Okay, I had a look at my errors log file, and:
[29-Dec-2003 13:43:16] PHP Warning: php_hostconnect: connect failed in c:\program files\pdev\www\trial\rss-parser.php on line 24
[29-Dec-2003 13:43:16] PHP Warning: file("http://www.stopdesign.com/index.xml") - Bad file descriptor in c:\program files\pdev\www\trial\rss-parser.php on line 24
[29-Dec-2003 13:43:16] PHP Warning: Bad arguments to implode() in c:\program files\pdev\www\trial\rss-parser.php on line 24
[29-Dec-2003 13:43:16] PHP Warning: Sablotron error on line 1: XML parser error 3: no element found in c:\program files\pdev\www\trial\rss-parser.php on line 32
It can't connect. Could this be something to do with the fact that I've got a firewall going?

12-29-2003, 03:44 PM
firstly check that allow_url_fopen = 1 (or 'On') in the php.ini

either a proxy server or a firewall could be an issue..

check by seeing if this works...

echo implode( '' , file( 'http://www.google.com' ) );

else you may need to reconfigure your firewall , or to get around proxies possibly use a http client like Snoopy (snoopy.sourceforge.net)