[ 
https://issues.apache.org/jira/browse/XERCESJ-1604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13571575#comment-13571575
 ] 

Maurizio Merli edited comment on XERCESJ-1604 at 2/5/13 7:17 PM:
-----------------------------------------------------------------

Maybe it's not a bug, it simply became very very slow because of this method 
"org.apache.xerces.dom.CharacterDataImpl.appendData(String)"

    public void appendData(String data) {

        if (isReadOnly()) {
            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 
msg);
        }
        if (data == null) {
            return;
        }
        if (needsSyncData()) {
            synchronizeData();
        }
        
        setNodeValue(this.data + data);

    } // appendData(String)

But why if I expand the node later in deferred mode it is very quick?
Maybe because it know the size of the part? But if it is so, why you don't 
create the CDATA text using a stringbuilder when deferred is disabled?

                
      was (Author: dashie):
    The test class is this:


package test;

import java.io.File;
import java.io.FileInputStream;
import java.util.concurrent.TimeUnit;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;

public class BigCData {

        public static void main(String[] args) throws Exception {
                
                DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance(
                                
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl", 
BigCData.class.getClassLoader());
                factory.setNamespaceAware(true);
                factory.setValidating(false);
                try {
                        
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion";, 
false);
                        
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd";,
 false);
                        // 
factory.setAttribute("http://apache.org/xml/properties/input-buffer-size";, new 
Integer(100000000));
                } catch (Throwable ex) {
                        System.err.println("Cannot set IGNORE DTD feature. You 
can have performace problems.");
                }

                XPathExpression xpath = 
XPathFactory.newInstance().newXPath().compile("//style");

                long t0 = System.nanoTime();
                File file = new 
File("/Users/maurizio/Downloads/web_dossier_mars.xml");
                Document doc = factory.newDocumentBuilder().parse(new 
FileInputStream(file));
                long dt = System.nanoTime() - t0;

                System.out.println(TimeUnit.NANOSECONDS.toMillis(dt) + " parse 
> " + doc);

                String nodeValue = xpath.evaluate(doc);

                dt = System.nanoTime() - t0;
                System.out.println(TimeUnit.NANOSECONDS.toMillis(dt) + " xpath 
> " + nodeValue.length());
        }

}

                  
> Big CDATA section cause a loop
> ------------------------------
>
>                 Key: XERCESJ-1604
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1604
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: DOM (Level 3 Core)
>            Reporter: Maurizio Merli
>         Attachments: web_dossier_mars.rar
>
>
> Parsing a document with a big CDATA section (about 25MB) with the feature 
> "http://apache.org/xml/features/dom/defer-node-expansion"; set to false, cause 
> an infinite loop.
> Use this test class on the attachment.
> package test;
> import java.io.File;
> import java.io.FileInputStream;
> import java.util.concurrent.TimeUnit;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.xpath.XPathExpression;
> import javax.xml.xpath.XPathFactory;
> import org.w3c.dom.Document;
> public class BigCData {
>       public static void main(String[] args) throws Exception {
>               
>               DocumentBuilderFactory factory = 
> DocumentBuilderFactory.newInstance(
>                               
> "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl", 
> BigCData.class.getClassLoader());
>               factory.setNamespaceAware(true);
>               factory.setValidating(false);
>               try {
>                       
> factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion";, 
> false);
>                       
> factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd";,
>  false);
>                       // 
> factory.setAttribute("http://apache.org/xml/properties/input-buffer-size";, 
> new Integer(100000000));
>               } catch (Throwable ex) {
>                       System.err.println("Cannot set IGNORE DTD feature. You 
> can have performace problems.");
>               }
>               XPathExpression xpath = 
> XPathFactory.newInstance().newXPath().compile("//style");
>               long t0 = System.nanoTime();
>               File file = new 
> File("/Users/maurizio/Downloads/web_dossier_mars.xml");
>               Document doc = factory.newDocumentBuilder().parse(new 
> FileInputStream(file));
>               long dt = System.nanoTime() - t0;
>               System.out.println(TimeUnit.NANOSECONDS.toMillis(dt) + " parse 
> > " + doc);
>               String nodeValue = xpath.evaluate(doc);
>               dt = System.nanoTime() - t0;
>               System.out.println(TimeUnit.NANOSECONDS.toMillis(dt) + " xpath 
> > " + nodeValue.length());
>       }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to