downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SimpleXMLElement> <Einzubindende Datei example.php mit XML-String
Last updated: Fri, 30 Oct 2009

view this page in

Dealing with XML errors

Dealing with XML errors when loading documents is a very simple task. Using the libxml functionality it is possible to suppress all XML errors when loading the document and then iterate over the errors.

The libXMLError object, returned by libxml_get_errors(), contains several properties including the message, line and column (position) of the error.

Beispiel #1 Loading broken XML string

<?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;
    }
}

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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



add a note add a note User Contributed Notes
Dealing with XML errors
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites