I'm creating an XML file on your own using PHP's SimpleXML Object. But I get this error when validating the document: 'Can not find promise of element "example".'

This is actually the code that's creating the XML document:

    $xml = new SimpleXMLElement('<example></example>');
    $xml->addChild('producers');

    foreach($producers as $i=>$producer){
       $name = get_the_title($producer->ID);
       $owner = get_post_meta($producer->ID, '_producer_contact_name', true);
       $phone = get_post_meta($producer->ID, '_producer_phone', true);
       $fax = get_post_meta($producer->ID, '_producer_fax', true);
       $email = get_post_meta($producer->ID, '_producer_email', true);
       $website = get_post_meta($producer->ID, '_producer_website', true);
       $address = get_post_meta($producer->ID, '_producer_address', true);

       $xml->producers->addChild('producer');
       $xml->producers->producer[$i]->addChild('name', $name);
       $xml->producers->producer[$i]->addChild('owner', $owner);
       $xml->producers->producer[$i]->addChild('phone', $phone);
       $xml->producers->producer[$i]->addChild('fax', $fax);
       $xml->producers->producer[$i]->addChild('email', $email);
       $xml->producers->producer[$i]->addChild('website', $website);
       $xml->producers->producer[$i]->addChild('civic', $address[0]); 
       $xml->producers->producer[$i]->addChild('mailing', $address[1]); 
       $xml->producers->producer[$i]->addChild('town', $address[2]); 
       $xml->producers->producer[$i]->addChild('province', $address[3]); 
       $xml->producers->producer[$i]->addChild('postal', $address[4]);           
    }

    $open = fopen($file, 'w') or die ("File cannot be opened.");
    fwrite($open, $xml->asXML());
    fclose($open);

The XML that's created is:

<?xml version="1.0"?>
   <example>
      <producers>
         <producer>
            <name></name>
            <phone></phone>
            <fax></fax>
            <email></email>
            <website></website>
            <civic></civic>
            <mailing></mailing>
            <town></town>
            <province></province>
            <postal></postal>
         </producer>
      </producers>
   </example>

Any help could be appreciated! Thanks

An XML file needs something to validate it against, a Document Type Definition (DTD) or perhaps an XML Schema. You are not supplying any, so validation (i.e., checking when the structure/content from the XML document adjusts towards the rules established within the DTD/Schema) doesn't seem possible.

Or have you just desire to look for well-formedness (i.e., checking that tags are closed correctly, that you will find no illegal figures anywhere etc.)?

To be able to validate an XML document, you'll need a DTD (or XML Schema) which describes the way a valid document appears like. You'll need write a DTD example.dtd for the XML application, and only create it for the validator or include it inside your XML document, by prefixing it with

<!DOCTYPE example SYSTEM "example.dtd">

Since SimpleXML doesn't support doctypes, you have to either by hand prefix the above mentioned line or use php's DOM extension. Fortunately, you are able to import the SimpleXML fragment to DOM with [cde].