php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16193 XML parser error 3: no element found
Submitted: 2002-03-20 17:19 UTC Modified: 2002-06-28 22:15 UTC
From: kdesormeaux at atre dot net Assigned:
Status: Closed Package: XSLT related
PHP Version: 4.3.0-dev OS: windows2000/linux...
Private report: No CVE-ID: None
 [2002-03-20 17:19 UTC] kdesormeaux at atre dot net
Here is the error:
Warning: Sablotron error on line 1: XML parser error 4: not well-formed (invalid token) in c:\Inetpub\wwwroot\localData\tools\xml\example\xsl\xml.php on line 7
Error: XML parser error 4: not well-formed (invalid token)

Now the code imma going to show has been tried many different ways all with the exact same error message.

Here is one sample of the php code...

$xh = xslt_create();
$args = array();
$params = array( 'foo' => 'bar' );
$result = xslt_process($xh,
'c:\Inetpub\wwwroot\localData\tools\xml\example\xsl\xml.xml','c:\Inetpub\wwwroot\localData\tools\xml\example\xsl\xml.xml',NULL, $args,$params);
if ($result)
{
 print $result;
} else {
 print "Error: ".xslt_error($xh);
}
@xslt_free($xh);
exit;


here is the xml.xml

<?xml version="1.0"?>
<catalog>
	<cd>
		<title>str_title</title>
		<artist>str_artist</artist>
	</cd>
</catalog>


here is the xsl.xsl file

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
<xsl:value-of select="artist"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


I have no idea what is going on here.  Read the peeps where able to run this on windows but no go here.  Maybe my dlls are baffed????

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-20 17:24 UTC] derick@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php
 [2002-05-30 09:05 UTC] urs at circle dot ch
System:
- Windows 2000
- Apache 1.3.24, Apache Release 10324100
- PHP as apache module
- PHP 4.3.0-dev
- Xslt Support enabled

Discussed earlier on bugs.php.net i found the code below, which is said to work. Running the script in command line mode I get - always - the same error:

C:\www\www-xml>php -f test.php

Warning: Sablotron error on line 1: XML parser error 3: no element found in test.php on line 23

Line 23 is the line with $xh = xslt_create();.

-urs

--
<?php
// http://bugs.php.net/bug.php?id=16993

$xml = <<< END
<?xml version="1.0" encoding="ISO-8859-2"?>
<ROOT>
<IMPORTANT>Very important ? ? ? </IMPORTANT>
</ROOT>
END;

$xsl = <<<END
<?xml version="1.0" encoding="ISO-8859-2"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="ROOT">
  <B><xsl:value-of select="IMPORTANT"/></B>
</xsl:template>
</xsl:stylesheet>
END;

$arguments = array('/_xml' => $xml,'/_xsl' => $xsl);
$xh = xslt_create();
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments );
echo $result;
?>
 [2002-06-13 05:48 UTC] chregu@php.net
The same problem here.

Code which works very fine under 4.2 just spits out:

Warning: Sablotron error on line 1: XML parser error 3: no element found in xslt.php on line 62

BC-break? or a real bug?

chregu
 [2002-06-24 13:04 UTC] 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)
 [2002-06-28 21:47 UTC] imajes@php.net
this isn't critical.
 [2002-06-28 22:15 UTC] sniper@php.net
This should be fixed now as the related files were reverted
back to the 4.2.1 level.

 [2003-05-24 08:23 UTC] 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 :)
 [2004-03-13 18:36 UTC] 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!
 [2004-06-03 17:32 UTC] andres_chacin at cantv dot net
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;

	}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 19:01:32 2024 UTC