Incorrect XML error - PHP generated XML page

I made a PHP page to dynamically generate an XML page for my dHTMLxTree app. It’s pulling data from a different server, so the .php file that I’m calling is on a different physical server.



The call to the XML file is:

tree1.loadXML(“http://www.myurl.com/scnavxml.xml”,function(){tree1.loadOpenStates()});



The PHP file contains the following:

<?php



if ( stristr($_SERVER[“HTTP_ACCEPT”],“application/xhtml+xml”) ) {

header(“Content-type: application/xhtml+xml”);

} else {

header(“Content-type: text/xml”);

}

echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");



$connect=mysql_connect(“localhost”,“user”,“pass”);

if(!$connect) die(“Couldn’t connect to MySQL Server”);

$result=mysql_select_db(“database”) or die(“Couldn’t connect to MySQL Database “); ?>





        

<?    $query = “select * from products where (productfor=1 or productfor=0) and status=1 and state<>4”;

    $dps = mysql_query(”$query and type=‘1’ and prodid<>36 and prodid<>175 and prodid<>109 and prodid<>156 and prodid<>134 and prodid<>165 and prodid<>260 and prodid<>265 order by disOrder desc”);

    if ($dp = mysql_fetch_array($dps)) { ?>

    

    

        /cart.php?type=1

        

<?         do { ?>

        

        

            /cart.php?prodid=<? echo $dp['prodid']; ?>

        

            

<?         } while ($dp = mysql_fetch_array($dps)); ?>

    

<?     }

    

    $cmls = mysql_query("$query and (prodid=36 or prodid=175 or prodid=109 or prodid=134 or prodid=156 or prodid=165 or prodid=260 or prodid=265) order by disOrder desc");

    if ($cml = mysql_fetch_array($cmls)) { ?>

    

    

        /cart.php?type=2

        

<?         do { ?>

        

        

            /cart.php?prodid=<? echo $cml['prodid']; ?>

        

            

<?         } while ($cml = mysql_fetch_array($cmls)); ?>

    

<?     }

    

    $mats = “select * from products where (productfor=1 or productfor=0) and status=1 and state<>4”;

    $materials = mysql_query("$query and type=‘0’ order by disOrder desc");

    if ($mat = mysql_fetch_array($materials)) { ?>

    

    

        /cart.php?type=3

        

<?         do { ?>

        

        

            /cart.php?prodid=<? echo $mat['prodid']; ?>

        

            

<?         } while ($mat = mysql_fetch_array($materials)); ?>

    

<?    } ?>











Now whenever I try to load the page it comes up with alert boxes saying:

Error Type: LoadXML

Description: Incorrect XML



and then…

Error Type: DataStructure

Description: XML reffers to not existing parent



I’m having a really tough time getting this to work…the XML file seems to be created fine, so why are these errors coming up?

Both html page and xml file must be loaded from the same server, browser doesn’t allow to operate with data from server different from the server of master html page. ( cross domain security )

In case, when data loaded from the same server, the most common issues for incorrect XML error
- incorrect content type ( you can try to always use Content-type:text/xml )
- whitespaces before starting <?xml declaration ( FF specific )