#16193 [Com]: XML parser error 3: no element found

From: Date: Thu, 03 Jun 2004 15:32:29 +0000
Subject: #16193 [Com]: XML parser error 3: no element found
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-60327@lists.php.net to get a copy of this message
ID: 16193 Comment by: andres_chacin at cantv dot net Reported By: kdesormeaux at atre dot net Status: Closed Bug Type: XSLT related Operating System: windows2000/linux... PHP Version: 4.3.0-dev New Comment: Hello everybody! I think I have found a way to solve this Error 'XML parser error 4: not well-formed (invalid token)'. Test this method. function XSL_transformation($XMLFile,$XSLFile,$ResultFile,$xsl_params){ $Str = ''; $xp = xslt_create() or trigger_error('Could not create XSLT process.', E_USER_ERROR); xslt_set_encoding($xp, 'ISO-8859-1'); // read the files into memory $xsl_string = join('', file($XSLFile)); $xml_string = join('', file($XMLFile)); // set the argument buffer $arg_buffer = array('/xml' => $xml_string, '/xsl' => $xsl_string); // process the two files to get the desired output if (($Str = xslt_process($xp, 'arg:/xml', 'arg:/xsl', NULL, $arg_buffer, $xsl_params))){ //Saves transformation result into '$ResultFile' $fp = fopen($ResultFile,"w+"); fwrite($fp,$Str); fclose($fp); return true; } return false; } Previous Comments: ------------------------------------------------------------------------ [2004-03-13 18:36:42] southen-antispam- at pipeline dot com Ok well I am getting something like this with the following code, and I'm running Redhat9 with PHP 4.3.4. My error message is Warning: Sablotron error on line 1: XML parser error 3: no element found in /home/httpd/vhosts/noctambus.com/httpdocs/reviews/xml/standardbrowser.php on line 85 My code is: /* transform method */ function transform() { $arguments = array( '/_xml' => $this->xml, '/_xsl' => $this->xsl ); $this->setOutput( xslt_process($this->processor, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments) ); $this->setError($err); } Can someone suggest a workaround? Thanks! ------------------------------------------------------------------------ [2003-05-24 08:23:47] drm-nospam- at -nospam-melp-dot-nl dot nospam [PHP 4.2.2, Windows XP] Here are my findings with the same bugs: The documentation on xslt_set_base () states that you must provide an file:// prefix with setting the base. It seems that you should provide the same prefix when passing files to xslt_process (). The following works fine with me, using the "Very important" example from above with local xml and xslt files, named 'sample.xml' and 'sample.xsl' respectively: <?php # create XSLT processor $xsltProcessor = xslt_create (); # generate filebase from working directory $fileBase = 'file://' . getcwd () . '/'; # process the 'sample.xml' and 'sample.xsl' files $result = xslt_process ( $xsltProcessor, $fileBase . 'sample.xml', $fileBase . 'sample.xsl' ); # print the result if ( $result ) { echo 'Success ...'; echo '<pre>', "\n"; echo htmlentities ( $result ); echo '</pre>'; } else { echo 'Fail due to error: ' . xslt_error($xh); } # free the processor resource xslt_free ( $xsltProcessor ); ?> Alternatively, you can use the xslt_set_base function to provide the processor with an explicit working directory: <?php # create XSLT processor $xsltProcessor = xslt_create (); # generate filebase from working directory $fileBase = 'file://' . getcwd () . '/'; # point xslt process base to working directory xslt_set_base ( $xsltProcessor, $fileBase ); # process the 'sample.xml' and 'sample.xsl' files $result = xslt_process ( $xsltProcessor, 'sample.xml', 'sample.xsl' ); # print the result if ( $result ) { echo 'Success ...'; echo '<pre>', "\n"; echo htmlentities ( $result ); echo '</pre>'; } else { echo 'Fail due to error: ' . xslt_error($xh); } # free the processor resource xslt_free ( $xsltProcessor ); ?> --- Hope some people will profit from this, at least i found a working solution :) ------------------------------------------------------------------------ [2002-06-28 22:15:34] sniper@php.net This should be fixed now as the related files were reverted back to the 4.2.1 level. ------------------------------------------------------------------------ [2002-06-28 21:47:18] imajes@php.net this isn't critical. ------------------------------------------------------------------------ [2002-06-24 13:04:34] chregu@php.net Changed title Somehow two different bugs got into here... Let's name it after the real bug... (or should i open a new one) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/16193 -- Edit this bug report at http://bugs.php.net/?id=16193&edit=1

« previous php.bugs (#60327) next »