Problem validating XML

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
handro1104
Forum Newbie
Posts: 2
Joined: Tue Feb 26, 2013 2:01 pm

Problem validating XML

Post 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>".
Your help will be greatly appreciated,

Alejandro Barrero
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem validating XML

Post by Celauran »

$xmlSchema isn't defined. Typo in your load call, also: $xmlFilePatht.
Post Reply