Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ankit on Aug 03, 2009 02:14
open dhtmlx forum
prob in loading xml

hi,
I am facing prob via loading xml file .i am creating dis file in jsp in scripletts "<% %>"
Wen i call "loadXML()" API from " gridDemo.jsp" , d control goes 2 "Process.jsp " but den it gives me alert like

error type-load xml
description- incorrect xml

and no exception is generated during dis procedure
Here is my src code.
=========================================================================
gridDemo.jsp

====================================================================
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlxgrid.css">
<script src="codebase/dhtmlxcommon.js"></script>
<script src="codebase/dhtmlxgrid.js"></script>
<script src="codebase/dhtmlxgridcell.js"></script>
<script src="codebase/ext/dhtmlxgrid_srnd.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Grid Demo</title>
</head>
<body onload="loadGrid()">

<div id="gridBox" style="width:500px;height:200px;"></div>

<script>
    function loadGrid()
    {
        var gridQString = 'Process.jsp';
        //var gridQString = 'gridData.xml';
     var mygrid = new dhtmlXGridObject('gridBox');
     mygrid.setImagePath("codebase/imgs/");
     mygrid.setHeader("Name,Type,Price");
     mygrid.setInitWidths("*,150,150");
     mygrid.setColAlign("left,left,right");
     mygrid.setSkin("modern");
     mygrid.init();
     mygrid.enableSmartRendering(true);
     mygrid.loadXML(gridQString);
    
    }
</script>
<input type="button" value="Load" onclick="loadGrid()">
</body>
</html>

/// end of jsp====================================

Process.jsp
========================================================================


<%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.OutputStream"%>

<%
//set content type and xml tag
int totalCount=1000;
int posStart=1;
try{

OutputStream outStream=response.getOutputStream();
PrintWriter printWriter=new PrintWriter(outStream, true);
printWriter.flush();
out.clear();

out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<rows>");
out.println("<row id=\"1\">");
out.println("<cell>");
out.println("Hello"); // value for product name
out.println("</cell>");
out.println("<cell>");
out.println("type1"); // value for type
out.println("</cell>");
out.println("<cell>");
out.println("40"); // value for price
out.println("</cell>");
out.println("</row>");

out.write("</rows>");

}
catch(Exception e)
{
    e.printStackTrace();
}
%>


Answer posted by dhxSupport on Aug 03, 2009 04:03
The reasons of "Incorrect xml" error could be:
*XML data is invalid ( invalid structure of XML ); 
    if some kind of server side error occurs, error or debug output may break valid xml data;
*invalid content type ( must be a text/xml for XML data );
*whitespaces before <?xml output;
*not escaped special characters, such as &, <, >; 
*incorrect encoding of data.

Solution:
*use debug version of dhtmlxcommon.js , which will show extended error info;
*load the same URL in separate browser window - it will show reason and location of error;
*correctly escape special characters in XML data.