Created
November 10, 2012 13:52
-
-
Save n5i/4051148 to your computer and use it in GitHub Desktop.
Checking if xml is valid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The function checks if xml is valid | |
function is_valid_xml ( $xml ) { | |
if( empty( $xml ) ){ | |
return null; | |
} | |
libxml_clear_errors(); | |
libxml_use_internal_errors( true ); | |
$doc = new DOMDocument('1.0', 'utf-8'); | |
$doc->loadXML( $xml ); | |
$errors = libxml_get_errors(); | |
return empty( $errors ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment