2

How to Improve xml parsing in GWT ?

My xml is as follows with 1 record

To parse 100 Record GWT takes 8 sec

Is there any way to improve performance ? Plz see my gwt code to parse xml

< Record productid="0" productidext="0" productkeyid="16000" productversion="1" isFEDRecord="false" validationstatus="" selected="false" accessmode="modify" isedited="false">

< RecordAttribute name="CINTEGERATTR" edited="false">

< Value>12345678< /Value>

< OldValue>12345678< /OldValue>

< /RecordAttribute>

< /Record>

My GWT parsing code is as follows:

private static List parseRecords(Document mainDOM, List records) { NodeList recordNodeList = mainDOM.getElementsByTagName("Record"); //Record node RecordInfo recordInfo= null;

    for(int i=0;i<recordNodeList.getLength();i++){ //iteration over record node

        recordInfo = new RecordInfo();
        recordInfo.setColumnCount(columnInfoList.size());
        recordInfo.setColumnInfoList(columnInfoList);
        HashMap<String, String> recordsColumnValueHashMap = new HashMap<String, String>();

        Element element = ((Element)recordNodeList.item(i));  //Record node


        NamedNodeMap recNodeMap = recordNodeList.item(i).getAttributes();
        if(i==0){

        }else{

            recordInfo.setProductid(recNodeMap.getNamedItem("productid").getNodeValue());
            recordInfo.setProductidext(recNodeMap.getNamedItem("productidext").getNodeValue());
            recordInfo.setProductkeyid(recNodeMap.getNamedItem("productkeyid").getNodeValue());
            recordInfo.setProductversion(Integer.parseInt(recNodeMap.getNamedItem("productversion").getNodeValue()));
            recordInfo.setFEDRecord(Boolean.parseBoolean(recNodeMap.getNamedItem("isFEDRecord").getNodeValue()));
            recordInfo.setValidationstatus(recNodeMap.getNamedItem("validationstatus").getNodeValue());
            recordInfo.setSelected(Boolean.parseBoolean(recNodeMap.getNamedItem("selected").getNodeValue()));
            recordInfo.setAccessmode(recNodeMap.getNamedItem("accessmode").getNodeValue());
            recordInfo.setIsedited(recNodeMap.getNamedItem("isedited").getNodeValue());
        NodeList recList = element.getElementsByTagName("RecordAttribute");


        for(int j=0;j<recList.getLength();j++){ //iterating all record attributes
            NodeList  child = recList.item(j).getChildNodes();

recordInfo.setColumnNameInRecord(recList.item(j).getAttributes().getNamedItem("name").getNodeValue()); recordInfo.setColumnInRecordEdited(Boolean.parseBoolean(recList.item(j).getAttributes().getNamedItem("edited").getNodeValue())); for(int k=0;k

                if("Value".equalsIgnoreCase(child.item(k).getNodeName())){
                    if(child.item(k).getFirstChild()!=null){
                        String value = child.item(k).getFirstChild().getNodeValue();
                    //System.out.println("Value =  "+child.item(k).getFirstChild().getNodeValue());
                    recordInfo.setValue(value);
                    String columnName = recList.item(j).getAttributes().getNamedItem("name").getNodeValue();
                    recordsColumnValueHashMap.put(columnName, value);
                }
                }
                if("OldValue".equalsIgnoreCase(child.item(k).getNodeName())){
                    if(child.item(k).getFirstChild()!=null){
                        String oldValue = child.item(k).getFirstChild().getNodeValue();
                    //System.out.println("oldValue  ="+child.item(k).getFirstChild().getNodeValue());
                    recordInfo.setOldValue(oldValue);
                    }
                }
            }

        }
         recordInfo.setRecordHashMap(recordsColumnValueHashMap);
        }

        records.add(recordInfo);
    }
    return records;
}
StackOverFlow
  • 4,486
  • 12
  • 52
  • 87

2 Answers2

3

are your running in development mode or have you compilded it to actuall JavaScript code. In my experince development mode runds 10 times slower then when it is cross compiled to JavaScript. Still 8s is alot! Have you used Speedtrace to see where most of the time is lost?

Stefan
  • 14,826
  • 17
  • 80
  • 143
  • Yes, I am parsing xml in Development mode. In Production mode it takes less time i.e 377 miliseconds only :). Why development takes too much time? Developer needs to test data on development mode . – StackOverFlow Aug 05 '11 at 20:35
  • 1
    the development mode interprets the code with the plugin. You send your code to the GWT plugin, the plugin looks what command it is and executes it in the browser. this way it can trigger breakpoints, get the current value of variables etc. so everything you expect from a debugger. You can even change your code and just have to refresh your browser to get the updates :). If you compile it to JavaScript GWT highly optimizes the code. This takes a lot of time but it runs fast (8s compared to 377ms^^) but the compilation takes >20 seconds so you don’t really want to use it for development^^ – Stefan Aug 05 '11 at 22:10
0

It seems highly unlikely that the 8sec is being spent parsing - my guess is that it is spent trying to find resources on the network such as a DTD access.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164