How to check for errors in an XML


I'm using the simplexml_load_string function to load a dynamic XML, but if there are formatting errors in this XML it only returns me false and I do not know where the error is, can I check this?

asked by Kenny Rafael 02.01.2014 в 14:21

2 answers


You can create a simple function to check if the XML is valid.

function is_valid_xml ( $xml ) {
    libxml_use_internal_errors( true );

    $doc = new DOMDocument('1.0', 'utf-8');

    $doc->loadXML( $xml );

    $errors = libxml_get_errors();

    return empty( $errors );
02.01.2014 / 14:44

According to the , if you load the

02.01.2014 в 14:29