本文介绍了Woodstox通过SimpleXML属性限制-如何设置它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让SimpleXML读取巨大的XML并遇到属性大小限制.

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

javax.xml.stream.XMLStreamException:超出最大属性大小限制(524288) 在com.ctc.wstx.sr.StreamScanner.constructLimitViolation(StreamScanner.java:2470)

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

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

如何强制Woodstox使用新的限制?

How can I force Woodstox to use a new limit?

推荐答案

我找到了一种可行的方法.我创建了自己的XMLInputFactory,它扩展了woodstox工厂,从而改变了有问题的限制.

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);
    }
}

然后只需在main中设置system属性.

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");           

这篇关于Woodstox通过SimpleXML属性限制-如何设置它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:48