2017-06-02 84 views
0

我使用StAX解析器解析非常大的XML文件,這個我已經寫禁用功能安全處理XML的

public class XmlWrite { 
public static void main(String[] args) throws 
            IOException,XMLStreamException { 
    FileWriter fw = null; 
    FileReader page = new FileReader("pages142"); 
    XMLInputFactory factory = XMLInputFactory.newInstance(); 
    //factory.setProperty(XMLConstants.FEATURE_SECURE_PROCESSING,false); 
    XMLEventReader eventReader = factory.createXMLEventReader(page); 
    boolean flag = false; 
    int no = 1; 
    while(eventReader.hasNext()) { 
     XMLEvent event = eventReader.nextEvent(); 
    ......... 

此代碼工作正常上一個小的輸入文件,但對於代碼一個大的文件時,它提供了以下錯誤

 Exception in thread "main" javax.xml.stream.XMLStreamException: 
     ParseError at [row,col]:[44018907,204] 
     Message: JAXP00010004: The accumulated size of entities is 
     "50,000,001" that exceeded the "50,000,000" limit set by 
     "FEATURE_SECURE_PROCESSING". 
      at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604) at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83) at XmlWrite.main(XmlWrite.java:28) 

我試過factory.setProperty,但同樣是不working.Is有在整個使用JVM禁用安全處理任何手段?

+0

我有同樣的問題。我找到了答案:[這裏](https://stackoverflow.com/questions/42991043/error-xml-sax-saxparseexception-while-parsing-a-xml-file-using-wikixmlj) –

回答

1

嘗試

factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,false) 

裁判:https://docs.oracle.com/javase/tutorial/jaxp/properties/scope.html

+0

但我試過了,它沒有工作。此語句位於4rth行的代碼 – Soumya

+0

請嘗試setFeature(),而不是setProperty()。 – RealHowTo

+0

其仍然沒有工作:(,這裏是我得到 XmlWrite.java:35錯誤:錯誤:無法找到符號 \t factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,FALSE); \t^ 符號:變量XMLConstants 位置: class XmlWrite – Soumya