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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:54:04+00:00 2026-06-04T10:54:04+00:00

I have been working on a project that displays data in an XML file.

  • 0

I have been working on a project that displays data in an XML file. (It’s kind of like an API). I know how to parse XML with PHP, and how to make an XML file in PHP, but they don’t work together. 🙂

Basically, I have two files: parse.php and xml.php.

xml.php grabs info from a MySQL database, and outputs it as XML.

parse.php loads and parses xml.php and outputs it as HTML.

If I run parse.php, it does not load xml.php. However, if I copy the outputted XML (from xml.php) and save it as a xml.xml file (and change the filename in parse.php to ‘xml.xml’) it works. I’d really appreciate any help.

Content of parse.php:

<?php

    $doc = "xml.php";

    $doc = @simplexml_load_file($doc) or die("Server Error: Recipe not found!");

    $title = $doc->title;

    echo $title

?>

Content of xml.php:

<?php

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

    $dbc = mysql... //gets data from database

    echo "<!DOCTYPE..."; //xml stuff here

    echo "<title>" . $dataFromMySQL . "</title>";

?>

The database connection works, and the DOCTYPE in the XML is ok, so that’s not the problem.

Again, I only get the problem when I generate XML dynamically using PHP. If it’s a .XML file, it works fine.

Can anyone help me?

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-06-04T10:54:05+00:00Added an answer on June 4, 2026 at 10:54 am
    @simplexml_load_file($doc);
    

    That is where your problem is. This does not execute xml.php, but attempts to parse that file — the PHP code that you’ve written — as XML. Obviously (since it isn’t XML) this won’t work.

    You have to find a way of getting the output from executing xml.php into parse.php.

    The easy way to do this would be to change all your echo calls into $xml .= calls, and simply include xml.php into parse.php.

    // xml.php
    $xml = '';
    $xml .= "<!DOCTYPE..."; //xml stuff here
    
    $output .= "<title>" . $dataFromMySQL . "</title>";
    
    // parse.php
    include('xml.php');
    
    simplexml_load_string($xml);
    

    Note that your problem here shows the foolishness of using the error suppression operator @. If you hadn’t used it, PHP would have shown you various errors which would have helped you to realise what the problem was.


    Addendum: it occurs to me that the best way actually is to forget about the pointless XML step along the way and just convert the database output into HTML.

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

Sidebar

Related Questions

I have been working on a project that has 2 interfaces - windows forms
Hey so I have been working on a project that I want to be
I have a project that I have been working on and am closing to
I have a project that I have been working on for a while, just
I have a django project that I have been working on as a solo
I have a console project that I have been working on. I added log4net
I have a project on github that I have been working on before. However,
I have been working with the Ebay api for a project and have found
I have been working on a project that requires a bar graph to be
I've got a django project working on a development server(ubuntu) that we have been

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.