Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Florent on Sep 30, 2008 08:43
open dhtmlx forum
Error type: LoadXML Description: Incorrect XML

Hi,
Trying to understand why I get a Error type: LoadXML Description: Incorrect XML message. I have no problem to display onscreen the xml data, it is only when I want to save the update or modification that I have this error. I am using this code to modify and save data in a MySQL database :


            mygrid = new dhtmlXGridObject('grid');
            mygrid.setImagePath("../../../dhtmlxGrid/codebase/imgs/");
            mygrid.setHeader("Identifiant,Postfiltre");
            mygrid.setInitWidths("200,300");
            mygrid.setColAlign("center,left");
            mygrid.setColTypes("ed,ed");
            mygrid.setColSorting("int,str");
            mygrid.setSkin("light");
            mygrid.init();
            mygrid.loadXML("grid_co.xml");        


            myDataProcessor = new dataProcessor("update_co.php");
            //myDataProcessor.enableDebug(true);
            myDataProcessor.enableDataNames(true);
            myDataProcessor.setVerificator(1);
            myDataProcessor.setUpdateMode("off");//available values: cell (default), row, off
            myDataProcessor.defineAction("error",myErrorHandler);
            myDataProcessor.setTransactionMode("GET");
            myDataProcessor.init(mygrid);
                        
            //Example of error handler. It gets <action> tag object as incomming argument.
            function myErrorHandler(obj)
            {
                alert("Error occured.\n"+obj.firstChild.nodeValue);
                myDataProcessor.stopOnError = true;
                return false;
            }


HERE ARE THE LINKS I USE TO ADD, MODIFY, etc. Items :

<a href="javascript:void(0)" onClick="mygrid.addRow((new Date()).valueOf(),[0,'','','',false,'na',false,''],mygrid.getRowIndex(mygrid.getSelectedId()))">Ajouter un élément</a>
<a href="javascript:void(0)" onClick="mygrid.deleteSelectedItem()">Supprimer un élément</a>
<input type="Button" onClick="myDataProcessor.sendData()" id="updatebutton" value="Sauvegarder" style="display:inline;">


HERE IS MY UPDATE_CO.PHP :

<?php

//start session (see get.php for details)
session_start();

if(!isset($_SESSION["id"]))
    $_SESSION["id"] = microtime();
    
//include db connection settings

$host="*************";
$user="*************";
$passeword="***********";

$link = mysql_connect($host, $user, $passeword);
mysql_select_db('**********',$link);

//FUNCTION TO USE IN THE CODE LATER

//XML HEADER

//include XML Header (as response will be in xml format)
//if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml");
        //header("Content-type: text/xml");
//}
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");

//PREPARE VALUES

if(!empty($_GET["Postfiltre"]))
{
    if(isset($_GET["!nativeeditor_status"]) && trim($_GET["!nativeeditor_status"])=="inserted")
    {
        //INSERT
        mysql_query("INSERT into mots_forum_blog value('".$_GET["Identifiant"]."','".$_GET["Postfiltre"]."')") or die("Erreur insertion : ".mysql_error());
            
        //set value to use in response
        $newId = mysql_insert_id();
        $action = "insert";
        
    }
    else
    {
        if(isset($_GET["!nativeeditor_status"]) && $_GET["!nativeeditor_status"]=="deleted")
        {
            //DELETE
            mysql_query("DELETE FROM mots_forum_blog WHERE id='".$_GET["Identifiant"]."'") or die("Erreur suppression : ".mysql_error());
            
            //set values to include in response
            $newId = $_GET["gr_id"];
            $action = "delete";
        }
        else
        {
            //UPDATE
            //update row
            mysql_query("UPDATE mots_forum_blog SET mot='".$_GET["Postfiltre"]."' WHERE id='".$_GET["Identifiant"]."'") or die("Erreur modification : ".mysql_error());
            
            //set values to include in response
            $newId = $_GET["gr_id"];
            $action = "update";
        }
    }
}
?>
<!-- response xml -->
<data>
    <?php
    if($newId!=0)
    {
        print("<action type='".$action."' sid='".$_GET["gr_id"]."' tid='".$newId."'/>");
    }
    else
    {
        print("<action type='error'>SQL query error</action>");
    }
    ?>
</data>

Thanks for your help
Florent
Answer posted by Support on Oct 01, 2008 03:21
a) please try to use header("Content-type: text/xml"); instead of   header("Content-type: application/xhtml+xml"); 
text/xml content type works for all versions of browsers, while xhtml+xml only for some 

b) the code which you are using seems correct, but please be sure that all data which outputed in XML is in the same encoding as defined in XML header.