Учебник по основам PHP. PHPBeginner



         

XML-интерпретация - часть 5


. xml_get_currentline_number($parser).

$openEntityNames): xml_parser_free($parser);

return FALSE: } }

xml_parser_free(Sparser). return TRUE; }

return FALSE: }

function new_xml_parser($file)

{ global $parser_file:

$xml_parser = xml_parser_create():

xml_parser_set_option

($xml_parser. XML_OPTION_CASE_FOLDING. 1):

xml_set_element_handler

($xml_parser. "startElement". "endElement"):

xml_set_character_datajiandler

($xml_parser. "characterOata");

xml_set_processing_instruction_handler($xml_parser.

"PIHandler"): xml_set_default_handler

($xml_parser. "defaultHandler"):

xml_set_external_entity_ref_handler

($xml_parser, "externalEntityRefHandler"):

if (!($fp = @fopen($file. "r"))) { return FALSE. }

if (!is_array($parser_file)) { settype($parser_file, "array"); }

Sparser_file[$xml_parser] =

$file. return array($xml_parser. $fp);}

//----------------------.......

if (!(list($xml_parser. $fp) =

new_xml_parser($file))) { dieC'could not open XML input"); }

print "<pre>"; while (Sdata =

freadUfp. 4096)) {

if (!xml_parse($xml_parser. Sdata. feof($fp)))

{ die(spnntf("XML error ^s at line *d\n". xml_error_string

(xml_get_error_code

($xml_parser)). xml_get_current_line_number($xml_parser)));} }

print "</pre>": print "parse completed";

xml_parser_free($xml_parser):

Содержимое файла xmltest.xml:

<?xml version='1.0">>

<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [

<!ENTITY plainEntity "FOO entity">

<!ENTITY systemEntity SYSTEM "xmltest2.xml"> ]>

<chapter> <TITLE>Title &plainEntity:</TITLE> <para>

<informaltable> <tgroup cols="3">

<tbody> <row><entry>al</entry>

<entry morerows="l">bl</entry>

<entry>cl</entry></row> <row><entry>a2</entry>




Содержание  Назад  Вперед