Woodstox via SimpleXML attribute limits - how to set them?

拜拜、爱过 提交于 2019-12-11 23:56:07

问题


I've been trying to get SimpleXML to read a huge XML and run into attribute size limit.

javax.xml.stream.XMLStreamException: Maximum attribute size limit (524288) exceeded at com.ctc.wstx.sr.StreamScanner.constructLimitViolation(StreamScanner.java:2470)

I've tried using a system property but it doesn't seem to pick it up.

-Djavax.xml.stream.XMLInputFactory=com.ctc.wstx.stax.WstxInputFactory -Dcom.ctc.wstx.maxAttributeSize=10000000

How can I force Woodstox to use a new limit?


回答1:


I found a way that works. I created my own XMLInputFactory that extends the woodstox factory that alters the problematic limit.

public class InputFactory extends WstxInputFactory {
    public InputFactory() {
        super();
        setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, Integer.MAX_VALUE);
    }
}

Then just set the system property in main.

// Force use of our custom XML input factory
    System.getProperties().put("javax.xml.stream.XMLInputFactory", "my.custom.InputFactory");           


来源:https://stackoverflow.com/questions/52879100/woodstox-via-simplexml-attribute-limits-how-to-set-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!