<?php /* * test_markup_parser.php * * @(#) $Header: /home/mlemos/cvsroot/markupparser/test_markup_parser.php,v 1.7 2009/07/24 08:30:37 mlemos Exp $ * */
require_once('markup_parser.php');
$message_file = ((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : 'test/sample/simple.html'); $markup=new markup_parser_class;
/* Set to 1 if the you need to track line numbers of errors or element * positions */ $markup->track_lines = 1;
$parameters=array( 'File'=>$message_file,
/* Read a markup from a string instead of a file */ /* 'Data'=>'<html><head><title>My HTML data string</title></head> <body><p>My HTML data string</p></body></html>', */ );
/* * The following lines are for testing purposes. * Remove these lines when adapting this example to real applications. */ if(defined('__TEST')) { if(IsSet($__test_options['parameters'])) $parameters = $__test_options['parameters']; $markup->buffer_length = (IsSet($__test_options['buffer_length']) ? $__test_options['buffer_length'] : 8000); $markup->track_lines = (IsSet($__test_options['track_lines']) ? $__test_options['track_lines'] : 0); }
if(($success = $markup->StartParsing($parameters))) { do { if(!($success = $markup->Parse($end, $elements))) break; $te = count($elements); for($e = 0; $e < $te; ++$e) var_dump($elements[$e]); } while(!$end); if($success) $success = $markup->FinishParsing(); } if(!$success) { echo 'Markup parsing error: '.$markup->error.' at position '.$markup->error_position; if($markup->track_lines && $markup->GetPositionLine($markup->error_position, $line, $column)) echo ' line '.$line.' column '.$column; echo "\n"; } for($warning = 0, Reset($markup->warnings); $warning < count($markup->warnings); Next($markup->warnings), $warning++) { $w = Key($markup->warnings); echo 'Warning: ', $markup->warnings[$w], ' at position ', $w; if($markup->track_lines && $markup->GetPositionLine($w, $line, $column)) echo ' line '.$line.' column '.$column; echo "\n"; } ?>
|