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?
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?
You can create a simple function to check if the XML is valid.
<?php
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 );
}
?>