Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:36:20+00:00 2026-05-27T04:36:20+00:00

I am creating an XML file from scratch using PHP’s SimpleXML Object. But I

  • 0

I am creating an XML file from scratch using PHP’s SimpleXML Object. But I am getting this error when validating the document: ‘Can not find declaration of element “example”.’

Here is the code that is 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 is produced is this:

<?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 would be appreciated! Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:36:21+00:00Added an answer on May 27, 2026 at 4:36 am

    An XML file needs something to validate it against, a Document Type Definition (DTD) or an XML Schema. You’re not providing any, so validation (i.e., checking if the structure/content of the XML document conforms to the rules set forth in the DTD/Schema) is impossible.

    Or did you just wish to check for well-formedness (i.e., checking that all tags are closed properly, that there are no illegal characters anywhere etc.)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a XML file from a database using PHP.. I am following
In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get
I'm creating a xml-file for display in Excel using _di_IXMLDocument. But for some tags
I have a DataTable that I'm creating an XML file from using .WriteXML(..), although
I am creating an xml file dynamiclly with php after I read data from
I'm creating a PostScript file from XML input using xsl-fo (Apache-FOP). I need also
I need help in creating a xml file from my php code. I created
I'm creating a SimpleXMLElement object from an XML file: $pages = new SimpleXMLElement('content.xml', LIBXML_NOCDATA,
I'm creating a Windows application which reads XML file from given server. This application
Basically, I am creating an XML file by taking the values from a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.