Categories | Question details Back To List | ||
loadXML error while creation? Displaying the data in the grid using the following method call mygrid.loadXML("../filename.xml"); This xml file is created at the server side when a checkbox is selected, the client picks it up and displays it in the grid.Its producing Error Type:LoadXML Description:Incorrect XML LoadXML error is generated ONLY when its tested on remote link,but not while the code is run localy on machine.Thought many possibilities,like timing issue,finally it seems that file is not even created. =>the file creation process is as follows private void fileCreation(ArrayList nameList) { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document doc = documentBuilder.newDocument(); Element root = doc.createElement("rows"); doc.appendChild(root); int count = 0; Iterator itr = nameList.iterator(); while (itr.hasNext()) { xxxDTO obj = (xxxDTO)itr.next(); if("".equals(obj.getNo().trim()) && "".equals(obj.getName().trim())) { continue; } count++; Element childElement = doc.createElement("row"); childElement.setAttribute("id",""+count); root.appendChild(childElement); Element rowChildElement = doc.createElement("cell"); childElement.appendChild(rowChildElement); rowChildElement.appendChild(doc.createTextNode("0")); Element rowChildElement2 = doc.createElement("cell"); childElement.appendChild(rowChildElement2); rowChildElement2.appendChild(doc.createTextNode(obj.getNo())); Element rowChildElement3 = doc.createElement("cell"); childElement.appendChild(rowChildElement3); rowChildElement3.appendChild(doc.createTextNode(obj.getName())); } TransformerFactory tranFactory = TransformerFactory.newInstance(); Transformer aTransformer = tranFactory.newTransformer(); Source src = new DOMSource(doc); String fileLoc = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); if(fileLoc.indexOf("WEB-INF") != -1) { fileLoc = fileLoc.substring(0,fileLoc.indexOf("WEB-INF")); } File file = new File(fileLoc+"/filename.xml"); Result dest = new StreamResult(file); aTransformer.transform(src, dest); } catch (FactoryConfigurationError fce) { System.out.println("Cannot get the DocumentBuilderFactory instance: " + fce.getMessage()); } catch (ParserConfigurationException pce) { System.out.println("Cannot get the DocumentBuilder instance" + pce.getMessage()); } catch(Exception e) { System.out.println(e.getMessage()); } } =>parsed using a jsp file <div style="height:250px;;width:375px;display: none;" id="myDiv" class="tableContainer" > <script> if(selectName == "true"){ owngrid = new dhtmlXGridObject('myDiv'); owngrid.setImagePath("../images/dhtmlxgrid/"); owngrid.setHeader(" ,no,name"); owngrid.setInitWidths("25,150,*"); owngrid.setColAlign("right,left,left"); owngrid.setColTypes("ch,ro,ro"); owngrid.setSkin("modern"); owngrid.setAwaitedRowHeight(25); owngrid.init(); owngrid.enableSmartRendering(true); owngrid.loadXML("../filename.xml"); owngrid.attachEvent("onCheck",doOnCheck); var myIndex = new Array(); function doOnCheck(rowId,cellInd,state) { ........ ........ } window.setTimeout('fn()', 1000); function fn() { ... ... } nameIndexLength = nameIndexSize; } } </script> </div> Can u pls help to fix why loadXML error is thrown in this case Answer posted by Support on Jan 20, 2009 09:05 The loadXML just fetch the data from server and returns the file value as it was provided, the only way to resolve problem - run loadXML command only when file is really created ( it possible to catch error and resend XML request - but it will be an ugly solution ) |