home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Parser.pod < prev    next >
Encoding:
Text File  |  2003-08-22  |  20.9 KB  |  734 lines

  1. =head1 NAME
  2.  
  3. XML::LibXML::Parser - Parsing XML Data with XML::LibXML
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.   $parser = XML::LibXML->new();
  8.   $doc = $parser->parse_file( $xmlfilename );
  9.   $doc = $parser->parse_fh( $io_fh );
  10.   $doc = $parser->parse_string( $xmlstring);
  11.   $doc = $parser->parse_html_file( $htmlfile );
  12.   $doc = $parser->parse_html_fh( $io_fh );
  13.   $doc = $parser->parse_html_string( $htmlstring );
  14.   $doc = $parser->parse_sgml_file( $sgmlfile );
  15.   $doc = $parser->parse_sgml_fh( $io_fh );
  16.   $doc = $parser->parse_sgml_string( $sgmlstring );
  17.   $fragment = $parser->parse_balanced_chunk( $wbxmlstring );
  18.   $fragment = $parser->parse_xml_chunk( $wbxmlstring );
  19.   $parser->process_xincludes( $doc );
  20.   $parser->processXIncludes( $doc );
  21.   $parser->parse_chunk($string, $terminate);
  22.   $parser->start_push();
  23.   $parser->push(@data);
  24.   $doc = $parser->finish_push( $recover );
  25.   $parser->validation(1);
  26.   $parser->recover(1);
  27.   $parser->expand_entities(0);
  28.   $parser->keep_blanks(0);
  29.   $parser->pedantic_parser(1)
  30.   $parser->line_numbers(1)
  31.   $parser->load_ext_dtd(1);
  32.   $parser->complete_attributes(1);
  33.   $parser->expand_xinclude(1);
  34.   $parser->load_catalog( $catalog_file );
  35.   $parser->base_uri( $your_base_uri );
  36.   $parser->gdome_dom(1);
  37.   $parser->match_callback($subref);
  38.   $parser->open_callback($subref);
  39.   $parser->read_callback($subref);
  40.   $parser->close_callback($subref);
  41.  
  42.  
  43. =head1 DESCRIPTION
  44.  
  45.  
  46. =head1 SYNOPSIS
  47.  
  48.   use XML::LibXML;
  49.   my $parser = XML::LibXML->new();
  50.   
  51.   my $doc = $parser->parse_string(<<'EOT');
  52.   <some-xml/>
  53.   EOT
  54.   my $fdoc = $parser->parse_file( $xmlfile );
  55.   
  56.   my $fhdoc = $parser->parse_fh( $xmlstream );
  57.   
  58.   my $fragment = $parser->parse_xml_chunk( $xml_wb_chunk );
  59.  
  60.  
  61. =head1 PARSING
  62.  
  63. A XML document is read into a datastructure such as a DOM tree by a piece of
  64. software, called parser. XML::LibXML currently provides four diffrent parser
  65. interfaces:
  66.  
  67.  
  68. =over 4
  69.  
  70. =item * A DOM Pull-Parser
  71.  
  72. =item * A DOM Push-Parser
  73.  
  74. =item * A SAX Parser
  75.  
  76. =item * A DOM based SAX Parser.
  77.  
  78. =back
  79.  
  80.  
  81. =head2 Creating a Parser Instance
  82.  
  83. XML::LibXML provides an OO interface to the libxml2 parser functions. Thus you
  84. have to create a parser instance before you can parse any XML data.
  85.  
  86. =over 4
  87.  
  88. =item B<new>
  89.  
  90.   $parser = XML::LibXML->new();
  91.  
  92. There is nothing much to say about the constructor. It simply creates a new
  93. parser instance.
  94.  
  95. Although libxml2 uses mainly global flags to alter the behaviour of the parser,
  96. each XML::LibXML parser instance has its own flags or callbacks and does not
  97. interfere with other instances.
  98.  
  99.  
  100.  
  101. =back
  102.  
  103.  
  104. =head2 DOM Parser
  105.  
  106. One of the common parser interfaces of XML::LibXML is the DOM parser. This
  107. parser reads XML data into a DOM like datastructure, so each tag can get
  108. accessed and transformed.
  109.  
  110. XML::LibXML's DOM parser is not only capable to parse XML data, but also
  111. (strict) HTML and SGML files. There are three ways to parse documents - as a
  112. string, as a Perl filehandle, or as a filename. The return value from each is a
  113. XML::LibXML::Document object, which is a DOM object.
  114.  
  115. All of the functions listed below will throw an exception if the document is
  116. invalid. To prevent this causing your program exiting, wrap the call in an
  117. eval{} block
  118.  
  119. =over 4
  120.  
  121. =item B<parse_file>
  122.  
  123.   $doc = $parser->parse_file( $xmlfilename );
  124.  
  125. This function reads an absolute filename into the memory. It causes XML::LibXML
  126. to use libxml2's file parser instead of letting perl reading the file such as
  127. with parse_fh(). If you need to parse files directly, this function would be
  128. the faster choice, since this function is about 6-8 times faster then
  129. parse_fh().
  130.  
  131.  
  132. =item B<parse_fh>
  133.  
  134.   $doc = $parser->parse_fh( $io_fh );
  135.  
  136. parse_fh() parses a IOREF or a subclass of IO::Handle.
  137.  
  138. Because the data comes from an open handle, libxml2's parser does not know
  139. about the base URI of the document. To set the base URI one should use
  140. parse_fh() as follows:
  141.  
  142.   my $doc = $parser->parse_fh( $io_fh, $baseuri );
  143.  
  144.  
  145. =item B<parse_string>
  146.  
  147.   $doc = $parser->parse_string( $xmlstring);
  148.  
  149. This function is similar to parse_fh(), but it parses a XML document that is
  150. available as a single string in memory. Again, you can pass an optional base
  151. URI to the function.
  152.  
  153.   my $doc = $parser->parse_stirng( $xmlstring, $baseuri );
  154.  
  155.  
  156. =item B<parse_html_file>
  157.  
  158.   $doc = $parser->parse_html_file( $htmlfile );
  159.  
  160. Similar to parse_file() but parses HTML (strict) documents.
  161.  
  162.  
  163. =item B<parse_html_fh>
  164.  
  165.   $doc = $parser->parse_html_fh( $io_fh );
  166.  
  167. Similar to parse_fh() but parses HTML (strict) streams.
  168.  
  169.  
  170. =item B<parse_html_string>
  171.  
  172.   $doc = $parser->parse_html_string( $htmlstring );
  173.  
  174. Similar to parse_file() but parses HTML (strict) strings.
  175.  
  176.  
  177. =item B<parse_sgml_file>
  178.  
  179.   $doc = $parser->parse_sgml_file( $sgmlfile );
  180.  
  181. Similar to parse_file() but parses SGML documents.
  182.  
  183.  
  184. =item B<parse_sgml_fh>
  185.  
  186.   $doc = $parser->parse_sgml_fh( $io_fh );
  187.  
  188. Similar to parse_file() but parses SGML streams.
  189.  
  190.  
  191. =item B<parse_sgml_string>
  192.  
  193.   $doc = $parser->parse_sgml_string( $sgmlstring );
  194.  
  195. Similar to parse_file() but parses SGML strings.
  196.  
  197.  
  198.  
  199. =back
  200.  
  201. Parsing HTML may causes problems, especially if the ampersand ('&') is used.
  202. This is a common problem if HTML code is parsed that contains links to
  203. CGI-scripts. Such links cause the parser to throw errors. In such cases libxml2
  204. still parses the entire document as there was no error, but the error causes
  205. XML::LibXML to stop the parsing process. However, the document is not lost.
  206. Such HTML documents should be parsed using the recover flag. By default
  207. recovering is deactivated.
  208.  
  209. The functions described above are implemented to parse well formed documents.
  210. In some cases a program gets well balanced XML instead of well formed documents
  211. (e.g. a XML fragment from a Database). With XML::LibXML it is not required to
  212. wrap such fragments in the code, because XML::LibXML is capable even to parse
  213. well balanced XML fragments.
  214.  
  215. =over 4
  216.  
  217. =item B<parse_balanced_chunk>
  218.  
  219.   $fragment = $parser->parse_balanced_chunk( $wbxmlstring );
  220.  
  221. This function parses a well balanced XML string into a
  222. XML::LibXML::DocumentFragment.
  223.  
  224.  
  225. =item B<parse_xml_chunk>
  226.  
  227.   $fragment = $parser->parse_xml_chunk( $wbxmlstring );
  228.  
  229. This is the old name of parse_balanced_chunk(). Because it may causes confusion
  230. with the push parser interface, this function should be used anymore.
  231.  
  232.  
  233.  
  234. =back
  235.  
  236. By default XML::LibXML does not process XInclude tags within a XML Document
  237. (see options section below). XML::LibXML allows to post process a document to
  238. expand XInclude tags.
  239.  
  240. =over 4
  241.  
  242. =item B<process_xincludes>
  243.  
  244.   $parser->process_xincludes( $doc );
  245.  
  246. After a document is parsed into a DOM structure, you may want to expand the
  247. documents XInclude tags. This function processes the given document structure
  248. and expands all XInclude tags (or throws an error) by using the flags and
  249. callbacks of the given parser instance.
  250.  
  251. Note that the resulting Tree contains some extra nodes (of type
  252. XML_XINCLUDE_START and XML_XINCLUDE_END) after successfully processing the
  253. document. These nodes indicate where data was included into the original tree.
  254. if the document is serialized, these extra nodes will not show up.
  255.  
  256. Remember: A Document with processed XIncludes differs from the original
  257. document after serialization, because the original XInclude tags will not get
  258. restored!
  259.  
  260. If the parser flag "expand_xincludes" is set to 1, you need not to post process
  261. the parsed document.
  262.  
  263.  
  264. =item B<processXIncludes>
  265.  
  266.   $parser->processXIncludes( $doc );
  267.  
  268. This is an alias to process_xincludes, but through a JAVA like function name.
  269.  
  270.  
  271.  
  272. =back
  273.  
  274.  
  275. =head2 Push Parser
  276.  
  277. XML::LibXML provides a push parser interface. Rather than pulling the data from
  278. a given source the push parser waits for the data to be pushed into it.
  279.  
  280. This allows one to parse large documents without waiting for the parser to
  281. finish. The interface is especially usefull if a program needs to preprocess
  282. the incoming pieces of XML (e.g. to detect document boundaries).
  283.  
  284. While XML::LibXML parse_*() functions force the data to be a wellformed XML,
  285. the push parser will take any arbitrary string that contains some XML data. The
  286. only requirement is that all the pushed strings are together a wellformed
  287. document. With the push parser interface a programm can interrupt the parsing
  288. process as required, where the parse_*() functions give not enough flexibility.
  289.  
  290. Different to the pull parser implemented in parse_fh() or parse_file(), the
  291. push parser is not able to find out about the documents end itself. Thus the
  292. calling program needs to indicate explicitly when the parsing is done.
  293.  
  294. In XML::LibXML this is done by a single function:
  295.  
  296. =over 4
  297.  
  298. =item B<parse_chunk>
  299.  
  300.   $parser->parse_chunk($string, $terminate);
  301.  
  302. parse_chunk() tries to parse a given chunk of data, which isn't nessecarily
  303. well balanced data. The function takes two parameters: The chunk of data as a
  304. string and optional a termination flag. If the termination flag is set to a
  305. true value (e.g. 1), the parsing will be stopped and the resulting document
  306. will be returned as the following exable describes:
  307.  
  308.   my $parser = XML::LibXML->new;
  309.   for my $string ( "<", "foo", ' bar="hello worls"', "/>") {
  310.        $parser->parse_chunk( $string );
  311.   }
  312.   my $doc = $parser->parse_chunk("", 1); # terminate the parsing
  313.  
  314.  
  315.  
  316. =back
  317.  
  318. Internally XML::LibXML provides three functions that controll the push parser
  319. process:
  320.  
  321. =over 4
  322.  
  323. =item B<start_push>
  324.  
  325.   $parser->start_push();
  326.  
  327. Initializes the push parser.
  328.  
  329.  
  330. =item B<push>
  331.  
  332.   $parser->push(@data);
  333.  
  334. This function pushs the data stored inside the array to libxml2's parse. Each
  335. entry in @data must be a normal scalar!
  336.  
  337.  
  338. =item B<finish_push>
  339.  
  340.   $doc = $parser->finish_push( $recover );
  341.  
  342. This function returns the result of the parsing process. If this function is
  343. called without a parameter it will complain about non wellformed documents. If
  344. $restore is 1, the push parser can be used to restore broken or non well formed
  345. (XML) documents as the following example shows:
  346.  
  347.   eval {
  348.       $parser->push( "<foo>", "bar" );
  349.       $doc = $parser->finish_push();    # will report broken XML
  350.   };
  351.   if ( $@ ) {
  352.      # ...
  353.   }
  354.  
  355. This can be anoing if the closing tag misses by accident. The following code
  356. will restore the document:
  357.  
  358.   eval {
  359.       $parser->push( "<foo>", "bar" );
  360.       $doc = $parser->finish_push(1);   # will return the data parsed
  361.                                         # unless an error happend
  362.   };
  363.   
  364.   print $doc->toString(); # returns "<foo>bar</foo>"
  365.  
  366. Of course finish_push() will return nothing if there was no data pushed to the
  367. parser before.
  368.  
  369.  
  370.  
  371. =back
  372.  
  373.  
  374. =head2 DOM based SAX Parser
  375.  
  376. XML::LibXML provides a DOM based SAX parser. The SAX parser is defined in
  377. XML::LibXML::SAX::Parser. As it is not a stream based parser, it parses
  378. documents into a DOM and traverses the DOM tree instead.
  379.  
  380. The API of this parser is exactly the same as any other Perl SAX2 parser. See
  381. XML::SAX::Intro for details.
  382.  
  383. Aside from the regular parsing methods, you can access the DOM tree traverser
  384. directly, using the generate() method:
  385.  
  386.   my $doc = build_yourself_a_document();
  387.   my $saxparser = $XML::LibXML::SAX::Parser->new( ... );
  388.   $parser->generate( $doc );
  389.  
  390. This is useful for serializing DOM trees, for example that you might have done
  391. prior processing on, or that you have as a result of XSLT processing.
  392.  
  393. WARNING
  394.  
  395. This is NOT a streaming SAX parser. As I said above, this parser reads the
  396. entire document into a DOM and serialises it. Some people couldn't read that in
  397. the paragraph above so I've added this warning.
  398.  
  399. If you want a streaming SAX parser look at the XML::LibXML::SAX man page
  400.  
  401.  
  402. =head1 SERIALIZATION
  403.  
  404. XML::LibXML provides some functions to serialize nodes and documents. The
  405. serialization functions themself are described at the XML::LibXML::Node manpage
  406. or the XML::LibXML::Document manpage. XML::LibXML checks three global flags
  407. that alter the serialization process:
  408.  
  409.  
  410. =over 4
  411.  
  412. =item * skipXMLDeclaration
  413.  
  414. =item * skipDTD
  415.  
  416. =item * setTagCompression
  417.  
  418. =back
  419.  
  420. of that three functions only setTagCompression is available for all
  421. serialization functions.
  422.  
  423. Because XML::LibXML does these flags not itself, one has to define them locally
  424. as the following example shows:
  425.  
  426.   local $XML::LibXML::skipXMLDeclaration = 1;
  427.   local $XML::LibXML::skipDTD = 1;
  428.   local $XML::LibXML::setTagCompression = 1;
  429.  
  430. If skipXMLDeclaration is defined and not '0', the XML declaration is omitted
  431. during serialization.
  432.  
  433. If skipDTD is defined and not '0', an existing DTD would not be serialized with
  434. the document.
  435.  
  436. If setTagCompression is defined and not '0' empty tags are displayed as open
  437. and closing tags ranther than the shortcut. For example the empty tag foo will
  438. be rendered as <foo></foo> rather than <foo/>.
  439.  
  440.  
  441. =head1 PARSER OPTIONS
  442.  
  443. LibXML options are global (unfortunately this is a limitation of the underlying
  444. implementation, not this interface). They can either be set using
  445. $parser->option(...), or XML::LibXML->option(...), both are treated in the same
  446. manner. Note that even two parser processes will share some of the same
  447. options, so be careful out there!
  448.  
  449. Every option returns the previous value, and can be called without parameters
  450. to get the current value.
  451.  
  452. =over 4
  453.  
  454. =item B<validation>
  455.  
  456.   $parser->validation(1);
  457.  
  458. Turn validation on (or off). Defaults to off.
  459.  
  460.  
  461. =item B<recover>
  462.  
  463.   $parser->recover(1);
  464.  
  465. Turn the parsers recover mode on (or off). Defaults to off.
  466.  
  467. This allows to parse broken XML data into memory. This switch will only work
  468. with XML data rather than HTML data. Also the validation will be switched off
  469. automaticly.
  470.  
  471. The recover mode helps to recover documents that are almost wellformed very
  472. efficiently. That is for example a document that forgets to close the document
  473. tag (or any other tag inside the document). The recover mode of XML::LibXML has
  474. problems though to restore documents that are more like well ballanced chunks.
  475.  
  476. XML::LibXML will only parse until the first fatal error occours.
  477.  
  478.  
  479. =item B<expand_entities>
  480.  
  481.   $parser->expand_entities(0);
  482.  
  483. Turn entity expansion on or off, enabled by default. If entity expansion is
  484. off, any external parsed entities in the document are left as entities.
  485. Probably not very useful for most purposes.
  486.  
  487.  
  488. =item B<keep_blanks>
  489.  
  490.   $parser->keep_blanks(0);
  491.  
  492. Allows you to turn off XML::LibXML's default behaviour of maintaining
  493. whitespace in the document.
  494.  
  495.  
  496. =item B<pedantic_parser>
  497.  
  498.   $parser->pedantic_parser(1)
  499.  
  500. You can make XML::LibXML more pedantic if you want to.
  501.  
  502.  
  503. =item B<line_numbers>
  504.  
  505.   $parser->line_numbers(1)
  506.  
  507. If this option is activated XML::LibXML will store the line number of a node.
  508. This gives more information where a validation error occoured. It could be also
  509. used to find out about the position of a node after parsing (see also
  510. XML::LibXML::Node::line_number())
  511.  
  512. By default line numbering is switched off (0).
  513.  
  514.  
  515. =item B<load_ext_dtd>
  516.  
  517.   $parser->load_ext_dtd(1);
  518.  
  519. Load external DTD subsets while parsing.
  520.  
  521.  
  522. =item B<complete_attributes>
  523.  
  524.   $parser->complete_attributes(1);
  525.  
  526. Complete the elements attributes lists with the ones defaulted from the DTDs.
  527. By default, this option is enabled.
  528.  
  529.  
  530. =item B<expand_xinclude>
  531.  
  532.   $parser->expand_xinclude(1);
  533.  
  534. Expands XIinclude tags imidiatly while parsing the document. This flag assures
  535. that the parser callbacks are used while parsing the included document.
  536.  
  537.  
  538. =item B<load_catalog>
  539.  
  540.   $parser->load_catalog( $catalog_file );
  541.  
  542. Will use $catalog_file as a catalog during all parsing processes. Using a
  543. catalog will significantly speed up parsing processes if many external
  544. ressources are loaded into the parsed documents (such as DTDs or XIncludes).
  545.  
  546. Note that catalogs will not be available if an external entity handler was
  547. specified. At the current state it is not possible to make use of both types of
  548. resolving systems at the same time.
  549.  
  550.  
  551. =item B<base_uri>
  552.  
  553.   $parser->base_uri( $your_base_uri );
  554.  
  555. In case of parsing strings or file handles, XML::LibXML doesn't know about the
  556. base uri of the document. To make relative references such as XIncludes work,
  557. one has to set a separate base URI, that is then used for the parsed documents.
  558.  
  559.  
  560. =item B<gdome_dom>
  561.  
  562.   $parser->gdome_dom(1);
  563.  
  564. THIS FLAG IS EXPERIMENTAL!
  565.  
  566. Although quite powerful XML:LibXML's DOM implementation is limited if one needs
  567. or wants full DOM level 2 or level 3 support. XML::GDOME is based on libxml2 as
  568. well but provides a rather complete DOM implementation by wrapping libgdome.
  569. This allows you to make use of XML::LibXML's full parser options and
  570. XML::GDOME's DOM implementation at the same time.
  571.  
  572. To make use of this function, one has to install libgdome and configure
  573. XML::LibXML to use this library. For this you need to rebuild XML::LibXML!
  574.  
  575.  
  576.  
  577. =back
  578.  
  579.  
  580. =head2 Input Callbacks
  581.  
  582. If libxml2 has to load external documents during parsing, this may cause
  583. strange results, if the location is not a HTTP, FTP or relative location. To
  584. get around this limitation, one may add its own input handler, to open, read
  585. and close particular locations or URI classes.
  586.  
  587. The input callbacks are used whenever LibXML has to get something other than
  588. external parsed entities from somewhere. The input callbacks in LibXML are
  589. stacked on top of the original input callbacks within the libxml library. This
  590. means that if you decide not to use your own callbacks (see match()), then you
  591. can revert to the default way of handling input. This allows, for example, to
  592. only handle certain URI schemes.
  593.  
  594. Callbacks are only used on files, but not on strings or filehandles. This is
  595. because LibXML requires the match event to find out about which callback set is
  596. shall be used for the current input stream. LibXML can decide this only before
  597. the stream is open. For LibXML strings and filehandles are already opened
  598. streams.
  599.  
  600. The following callbacks are defined:
  601.  
  602. =over 4
  603.  
  604. =item B<match_callback>
  605.  
  606.   $parser->match_callback($subref);
  607.  
  608. If you want to handle the URI, simply return a true value from this callback.
  609.  
  610.  
  611. =item B<open_callback>
  612.  
  613.   $parser->open_callback($subref);
  614.  
  615. Open something and return it to handle that resource.
  616.  
  617.  
  618. =item B<read_callback>
  619.  
  620.   $parser->read_callback($subref);
  621.  
  622. Read a certain number of bytes from the resource. This callback is called even
  623. if the entire Document has already read.
  624.  
  625.  
  626. =item B<close_callback>
  627.  
  628.   $parser->close_callback($subref);
  629.  
  630. Close the handle associated with the resource.
  631.  
  632.  
  633.  
  634. =back
  635.  
  636. The following example explains the concept a bit. It is a purely fictitious
  637. example that uses a MyScheme::Handler object that responds to methods similar
  638. to an IO::Handle.
  639.  
  640.   $parser->match_callback(\&match_uri);
  641.     
  642.     $parser->open_callback(\&open_uri);
  643.     
  644.     $parser->read_callback(\&read_uri);
  645.     
  646.     $parser->close_callback(\&close_uri);
  647.     
  648.     sub match_uri {
  649.       my $uri = shift;
  650.       return $uri =~ /^myscheme:/;
  651.     }
  652.     
  653.     sub open_uri {
  654.       my $uri = shift;
  655.       return MyScheme::Handler->new($uri);
  656.     }
  657.     
  658.     sub read_uri {
  659.       my $handler = shift;
  660.       my $length = shift;
  661.       my $buffer;
  662.       read($handler, $buffer, $length);
  663.       return $buffer;
  664.     }
  665.     
  666.     sub close_uri {
  667.       my $handler = shift;
  668.       close($handler);
  669.     }
  670.  
  671. A more realistic example can be found in the "example" directory.
  672.  
  673. Since the parser requires all callbacks defined it is also possible to set all
  674. callbacks with a single call of callbacks(). This would implify the example
  675. code to:
  676.  
  677.   $parser->callbacks( \&match_uri, \&open_uri, \&read_uri, \&close_uri);
  678.  
  679. All functions that are used to set the callbacks, can also be used to retrieve
  680. the callbacks from the parser.
  681.  
  682. Optionaly it is possible to apply global callback on the XML::LibXML class
  683. level. This allows multiple parses to share the same callbacks. To set these
  684. global callbacks one can use the callback access functions directly on the
  685. class.
  686.  
  687.   XML::LibXML->callbacks( \&match_uri, \&open_uri, \&read_uri, \&close_uri);
  688.  
  689. The previous code snippet will set the callbacks from the first example as
  690. global callbacks.
  691.  
  692.  
  693. =head1 ERROR REPORTING
  694.  
  695. XML::LibXML throws exceptions during parseing, validation or XPath processing
  696. (and some other occations). These errors can be catched by using eval blocks.
  697. The error then will be stored in $@. Alternatively one can use the
  698. get_last_error() function of XML::LibXML. It will return the same string that
  699. is stored in $@. Using get_last_error() makes it still nessecary to eval the
  700. statement, since these function groups will die() on errors.
  701.  
  702. Note, that the use of get_last_error() still requires eval blocks. XML::LibXML
  703. throws errors as they occour and does not wait if a user test for them. This is
  704. a very common misunderstanding in the use of XML::LibXML. If the eval is
  705. ommited, XML::LibXML will allways halt your script by "croaking" (see Carp man
  706. page for details).
  707.  
  708. Also note that an increasing number throws errors if bad data is passed. If you
  709. cannot asure valid data passed to XML::LibXML you should eval these functions.
  710.  
  711. get_last_error() can be called either by the class itself or by a parser
  712. instance:
  713.  
  714.   $errstring = XML::LibXML->get_last_error();
  715.   $errstring = $parser->get_last_error();
  716.  
  717. However, XML::LibXML exceptions are global. That means if get_last_error() is
  718. called on an parser instance, the last global error will be returned. This is
  719. not nessecarily the error caused by the parser instance itself.
  720.  
  721. =head1 AUTHORS
  722.  
  723. Matt Sergeant, 
  724. Christian Glahn, 
  725. =head1 VERSION
  726.  
  727. 1.56
  728.  
  729. =head1 COPYRIGHT
  730.  
  731. 2001-2002, AxKit.com Ltd; 2001-2003 Christian Glahn, All rights reserved.
  732.  
  733. =cut
  734.