PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 21, 2017 12:36 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem validating XML
PostPosted: Tue Jan 13, 2015 1:20 pm 
Offline
Forum Newbie

Joined: Tue Feb 26, 2013 3:01 pm
Posts: 2
Syntax: [ Download ] [ Hide ]
$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
Syntax: [ Download ] [ Hide ]
<?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


Top
 Profile  
 
PostPosted: Tue Jan 13, 2015 1:25 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6390
Location: Montreal, Canada
$xmlSchema isn't defined. Typo in your load call, also: $xmlFilePatht.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group