I encountered some problems to use isValid method with xml2assoc function.
I use this way to validate the entire xml file and put it into an associative array.
$xml = new XMLReader();
if (!$xml->xml($xml_string, NULL, LIBXML_DTDVALID)) {
echo "XML not valid: load error";
exit();
}
libxml_use_internal_errors(TRUE);
$xml_array = xml2assoc($xml);
$arErrors = libxml_get_errors();
$xml_errors = "";
foreach ($arErrors AS $xmlError) $xml_errors .= $xmlError->message;
if ($xml_errors != "") {
echo "XML not valid: ".$xml_errors;
exit();
}
//all ok