Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors.
[source language=“php“]
/**
* Takes XML string and returns a boolean result where valid XML returns true
*/
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 );
}
[/source]

This very cool!
I have also found this free online tool thats meant for xml validation, just input your code and press validate, http://www.liquid-technologies.com/FreeXmlTools/FreeXmlValidator.aspx
I prefer:
@$xml = simplexml_load_string(‚Santa‘);
if($xml){
// Do something with xml object.
$original = $xml->asXML();
}
This website was… how do you say it? Relevant!!
Finally I’ve found something that helped me. Thanks a lot!