Page 1 of 1

Problem validating XML

Posted: Tue Jan 13, 2015 12:20 pm
by handro1104

Code: Select all

$xml = new DOMDocument ();
$xml->load ( $xmlFilePatht );
if (! $xml->schemaValidate ( $xmlSchema )) {
	echo basename($xmlFilePath) . " is invalid according to " . basename($xmlSchema) . " the errors are:" . PHP_EOL;
	$errors = libxml_get_errors ();
	foreach ( $errors as $error ) {
		print libxml_display_error ( $error );
	}
The XML file is

Code: Select all

<?xml version="1.0"?>
<example>
	<child_string>This is an example.</child_string>
	<child_integer>Error condition.</child_integer>
</example>
I am getting the error message "<b>Error 1872</b>: The document has no document element. on line <b>-1</b>".

Re: Problem validating XML

Posted: Tue Jan 13, 2015 12:25 pm
by Celauran
$xmlSchema isn't defined. Typo in your load call, also: $xmlFilePatht.