loadXML error while creation?

Displaying the data in the grid using the following method call


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”);


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; }


     Element childElement = doc.createElement(“row”);



     Element rowChildElement = doc.createElement(“cell”);



     Element rowChildElement2 = doc.createElement(“cell”);



     Element rowChildElement3 = doc.createElement(“cell”);




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

Can u pls help to fix why loadXML error is thrown in this case

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 )