Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Shaun on May 21, 2009 19:20
open dhtmlx forum
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 <!-- ".mysql_error()." -->"); ?>

<tree id="0">
        
<?    $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)) { ?>
    
    <item text="Product Type 1" id="prod1" im0="group_16.gif" im1="open_16.gif" im2="foldr_16.gif" tooltip="Product Type 1">
        <userdata name="myurl">/cart.php?type=1</userdata>
        
<?         do { ?>
        
        <item text="<? echo $dp['prodname']; ?>" id="<? echo $dp['prodid']; ?>" im0="group_16.gif" tooltip="<? echo $dp['prodname']; ?>">
            <userdata name="myurl">/cart.php?prodid=<? echo $dp['prodid']; ?></userdata>
        </item>
            
<?         } while ($dp = mysql_fetch_array($dps)); ?>
    </item>
<?     }
    
    $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)) { ?>
    
    <item text="Product Type 2" id="prod2" im0="group_16.gif" im1="open_16.gif" im2="foldr_16.gif" tooltip="Product Type 2">
        <userdata name="myurl">/cart.php?type=2</userdata>
        
<?         do { ?>
        
        <item text="<? echo $cml['prodname']; ?>" id="<? echo $cml['prodid']; ?>" im0="group_16.gif" tooltip="<? echo $cml['prodname']; ?>">
            <userdata name="myurl">/cart.php?prodid=<? echo $cml['prodid']; ?></userdata>
        </item>
            
<?         } while ($cml = mysql_fetch_array($cmls)); ?>
    </item>
<?     }
    
    $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)) { ?>
    
    <item text="Product Type 3" id="prod3" im0="group_16.gif" im1="open_16.gif" im2="foldr_16.gif" tooltip="Product Type 3">
        <userdata name="myurl">/cart.php?type=3</userdata>
        
<?         do { ?>
        
        <item text="<? echo htmlspecialchars($mat['prodname']); ?>" id="<? echo $mat['prodid']; ?>" im0="group_16.gif" tooltip="<? echo htmlspecialchars($mat['prodname']); ?>">
            <userdata name="myurl">/cart.php?prodid=<? echo $mat['prodid']; ?></userdata>
        </item>
            
<?         } while ($mat = mysql_fetch_array($materials)); ?>
    </item>
<?    } ?>
</tree>




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?
Answer posted by Support on May 22, 2009 03:21
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 )