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 8974277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:38:45+00:00 2026-06-15T18:38:45+00:00

I am trying to get MySQL database into an xml file; here is my

  • 0

I am trying to get MySQL database into an xml file; here is my code:

  <?php

  header("Content-type: text/xml");

    include 'dbc.php';

      $query = "SELECT * FROM airports LIMIT 50";
      $result = mysql_query($query, $link)
      or die('Error querying database.');

  $xml = new SimpleXMLElement('<xml/>');

  while($row = mysql_fetch_assoc($result)) {
   $draw = $xml->addChild('draw');
   $draw->addChild('ident',htmlentities(iconv("UTF-8", "ISO-8859-1//IGNORE",$row['ident'])));
   $draw->addChild('name',htmlentities(iconv("UTF-8", "ISO-8859-1//IGNORE",$row['name'])));
  }

  mysql_close($link);
  $fp = fopen("links2.xml","wb");
  fwrite($fp,$xml->asXML());
  fclose($fp);

Here is the error Im getting:

  XML Parsing Error: no element found
  Location: /sql2xml2.php
  Line Number 1, Column 2: 
  -^

What am I doing wrong???

  • 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-06-15T18:38:47+00:00Added an answer on June 15, 2026 at 6:38 pm

    Your XML is considered invalid in your XML reader because of the thrown warning, thus the XML Parsing Error: junk after document element issue.

    As for the warning itself, you need to escape special entities (namely &, < and > in your content when adding it like that (using str_replace usually works well for only those 3 when it comes to XML, htmlentities may yield undesired effects, unless you supply PHP 5.4’s ENT_XML1 mode).

    Refer to a related answer for more information of why this happens.

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

Sidebar

Related Questions

I am trying to import a large text file into a MySQL database. The
I am trying to import my data form text file into mysql database. I
I am trying to save data from my xml file into the mysql database
I'm trying to get a std::string from my database using mysql connexion Here is
I'm trying to parse the contents of an remote XML file into MySQL, so
I'm trying to get a CSV imported into a MySQL database, where each new
I am trying to insert some e mails from a text file into MySQL
Trying to integrate netbeans with mysql database management into the IDE as explained here
I'm trying to insert XML data into mysql database. Issue I'm having is that
Im trying to get results from a mysql database to properly format into columns,

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.