开发者

How to Improve GWT XML parsing?

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 = re开发者_StackOverflow社区cList.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;
}


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜