0

Hi. 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.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Incognitus
0

That's because it is loading the actual xml.php file and not it's output. What you could do, is use cUrl to open and process xml.php and capture the output for processing.

1

you could make use of ajax, just echo the xml information then do whatever you want to do with the xml data

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.