You are here: Re: XSL error handling in PHP5 « PHP Programming Language « IT news, forums, messages
Re: XSL error handling in PHP5

Posted by Tony Marston on 10/18/51 11:45

I solved this problem years ago:

1) Have a standard error handler which can be invoked using trigger_error();
I call mine 'errorHandler'.

2) Create an alternative error handler for XML/XSL processing in PHP 5. I
call mine 'XML_errorHandler'

function XML_errorHandler ($errno, $errstr, $errfile, $errline,
$errcontext)
// deal with errors from XML or XSL functions.
{
// pass these details to the standard error handler
errorHandler (E_USER_ERROR, $errstr, $errfile, $errline,
$errcontext);
} // XML_errorHandler

3) Just before performing and XML/XSL processing switch to the alternative
error handler:

set_error_handler('XML_errorHandler');

4) Don't forget to switch back again afterwards:

set_error_handler('errorHandler');

All this code can be downloaded from my website in my sample application at
http://www.tonymarston.net/php-mysql/sample-application.html

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org


<al3x4nder@gmail.com> wrote in message
news:1145378276.288512.274260@v46g2000cwv.googlegroups.com...
> I`m need hanling XSLT errors in my script,
> before I`m use Sablotron, that has nice
> interface for it:
> ------------8<------------------
> function ProduceXHTML($xml, $xsl){
> $xh = xslt_create();
> xslt_set_encoding ($xh, CODE_PAGE);
> $arguments = array('/_xml' => $xml, '/_xsl' => $xsl);
> $result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL,
> $arguments);
> $this->error = (int)xslt_errno($xh);
> if($this->error){
> $errorMessage = sprintf("Cannot process XSLT document
> [code %d]: %s",
> xslt_errno($xh), xslt_error($xh));
> $this->AddErrorMessage(5, $errorMessage);
> }
>
> xslt_free($xh);
> }
>
> ------------8<------------------
>
> but now I`m ported my project
> in PHP5 and use XSLlib like this:
>
> ------------8<------------------
> function ProduceXHTML($xsltemplate){
> $xh = new XSLTProcessor();
> $xml = new DOMDocument();
> $xsl = new DOMDocument();
>
> $xsl->loadXML($this->LoadXSLT(TEMPLATES_ROOT.$xsltemplate));
> $xml->loadXML($this->xml);
>
> $xh->importStyleSheet($xsl);
> $xhtml=$xh->transformToXML($xml);
>
> if($this->IsDebug()){
> header('Content-type: text/xml');
> die($this->xml);
> }
> if ($xhtml) {
> $xhtml = str_replace("&amp;", "&", $xhtml);
> echo $xhtml;
> } else {
> /* commented, because PHPv5 used
> printf("Cannot process XSLT document [code %d]: %s",
> xslt_errno($xh), xslt_error($xh));
> */
> return false; // invalid XSL
> }
> unset($xh);
>
> }
> ------------8<------------------
> anybody know how I can track errors now?
>
> thanks and sorry for my English
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация