svn: /phpdoc/en/trunk/reference/simplexml/ examples.xml functions/simplexml-element-construct.xml functions/simplexml-load-file.xml
functions/simplexml-load-string.xml

From: Date: Fri, 31 Jul 2009 11:28:21 +0000
Subject: svn: /phpdoc/en/trunk/reference/simplexml/ examples.xml functions/simplexml-element-construct.xml functions/simplexml-load-file.xml
functions/simplexml-load-string.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4581@lists.php.net to get a copy of this message
bjori Fri, 31 Jul 2009 11:28:21 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=286588 Log: Add errorhandling docs Changed paths: U phpdoc/en/trunk/reference/simplexml/examples.xml U phpdoc/en/trunk/reference/simplexml/functions/simplexml-element-construct.xml U phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-file.xml U phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-string.xml Modified: phpdoc/en/trunk/reference/simplexml/examples.xml =================================================================== --- phpdoc/en/trunk/reference/simplexml/examples.xml 2009-07-31 11:26:42 UTC (rev 286587) +++ phpdoc/en/trunk/reference/simplexml/examples.xml 2009-07-31 11:28:21 UTC (rev 286588) @@ -4,6 +4,7 @@ <chapter xml:id="simplexml.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> &reftitle.examples; <section xml:id="simplexml.examples-basic"> + <title>Basic usage</title> <para> Many examples in this reference require an XML string. Instead of repeating this string in every example, we put it into a file which @@ -291,6 +292,63 @@ </example> </para> </section> + + <section xml:id="simplexml.examples-errors"> + <title>Dealing with XML errors</title> + <para> + Dealing with XML errors when loading documents is a very simple task. + Using the <link linkend="book.libxml">libxml</link> functionality it is + possible to suppress all XML errors when loading the document and then + iterate over the errors. + </para> + <para> + The <classname>libXMLError</classname> object, returned by + <function>libxml_get_errors</function>, contains several properties + including the <link linkend="libxmlerror.props.message">message</link>, + <link linkend="libxmlerror.props.line">line</link> and + <link linkend="libxmlerror.props.column">column</link> (position) of the + error. + </para> + <para> + <example> + <title>Loading broken XML string</title> + <programlisting role="php" xml:id="simplexml.examples.error"> +<![CDATA[ +<?php +libxml_use_internal_errors(true); +$sxe = simplexml_load_string("<?xml version='1.0'><broken><xml></broken>"); +if (!$sxe) { + echo "Failed loading XML\n"; + foreach(libxml_get_errors() as $error) { + echo "\t", $error->message; + } +} +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +Failed loading XML + Blank needed here + parsing XML declaration: '?>' expected + Opening and ending tag mismatch: xml line 1 and broken + Premature end of data in tag broken line 1 +]]> + </screen> + </example> + </para> + <section role="seealso"><!-- {{{ --> + &reftitle.seealso; + <para> + <simplelist> + <member><function>libxml_use_internal_errors</function></member> + <member><function>libxml_get_errors</function></member> + <member><xref linkend="class.libxmlerror" /></member> + </simplelist> + </para> + </section> + </section> + </chapter> <!-- Keep this comment at the end of the file Modified: phpdoc/en/trunk/reference/simplexml/functions/simplexml-element-construct.xml =================================================================== --- phpdoc/en/trunk/reference/simplexml/functions/simplexml-element-construct.xml 2009-07-31 11:26:42 UTC (rev 286587) +++ phpdoc/en/trunk/reference/simplexml/functions/simplexml-element-construct.xml 2009-07-31 11:28:21 UTC (rev 286588) @@ -89,6 +89,13 @@ Produces an <constant>E_WARNING</constant> error message for each error found in the XML data and throws an exception if errors were detected. </para> + <tip> + <para> + Use <function>libxml_use_internal_errors</function> to suppress all XML + errors, and <function>libxml_get_errors</function> to iterate over them + afterwards. + </para> + </tip> </refsect1> <refsect1 role="examples"> @@ -133,6 +140,8 @@ <simplelist> <member><function>simplexml_load_string</function></member> <member><function>simplexml_load_file</function></member> + <member><xref linkend="simplexml.examples-errors" /></member> + <member><function>libxml_use_internal_errors</function></member> </simplelist> </para> </refsect1> Modified: phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-file.xml =================================================================== --- phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-file.xml 2009-07-31 11:26:42 UTC (rev 286587) +++ phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-file.xml 2009-07-31 11:28:21 UTC (rev 286588) @@ -91,7 +91,22 @@ will return &false;. </para> </refsect1> - + + <refsect1 role="errors"><!-- {{{ --> + &reftitle.errors; + <para> + Produces an <constant>E_WARNING</constant> error message for each error + found in the XML data. + </para> + <tip> + <para> + Use <function>libxml_use_internal_errors</function> to suppress all XML + errors, and <function>libxml_get_errors</function> to iterate over them + afterwards. + </para> + </tip> + </refsect1><!-- }}} --> + <refsect1 role="examples"> &reftitle.examples; <para> @@ -139,6 +154,8 @@ <simplelist> <member><function>simplexml_load_string</function></member> <member><methodname>SimpleXMLElement::__construct</methodname></member> + <member><xref linkend="simplexml.examples-errors" /></member> + <member><function>libxml_use_internal_errors</function></member> </simplelist> </para> </refsect1> Modified: phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-string.xml =================================================================== --- phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-string.xml 2009-07-31 11:26:42 UTC (rev 286587) +++ phpdoc/en/trunk/reference/simplexml/functions/simplexml-load-string.xml 2009-07-31 11:28:21 UTC (rev 286588) @@ -82,6 +82,21 @@ </para> </refsect1> + <refsect1 role="errors"><!-- {{{ --> + &reftitle.errors; + <para> + Produces an <constant>E_WARNING</constant> error message for each error + found in the XML data. + </para> + <tip> + <para> + Use <function>libxml_use_internal_errors</function> to suppress all XML + errors, and <function>libxml_get_errors</function> to iterate over them + afterwards. + </para> + </tip> + </refsect1><!-- }}} --> + <refsect1 role="examples"> &reftitle.examples; <para> @@ -135,6 +150,8 @@ <simplelist> <member><function>simplexml_load_file</function></member> <member><methodname>SimpleXMLElement::__construct</methodname></member> + <member><xref linkend="simplexml.examples-errors" /></member> + <member><function>libxml_use_internal_errors</function></member> </simplelist> </para> </refsect1>

« previous php.doc.cvs (#4581) next »