如何使用XML Simple Framework跳过替换XML中的实体引用

时间:2013-05-08 18:42:46

标签: java xml simple-framework

我有一个XML文档,其中一个实体表示为字符串。

<URL IMAGEARTIST="" IMAGESUPPLIER="&copy;salzburg.info "
 URLDESCRIPTION="Skip the Line: Vatican Museums Walking Tour including Sistine Chapel, Raphael&apos;s Rooms and St Peter&apos;s"
 URLLINK="http://www.dynamic.viator.com/graphicslib/3731/SITours/skip-the-line-vatican-museums-walking-tour-including-sistine-chapel-in-rome-115004.jpg" URLType="IMAGE"/>

Persister在遇到“复制”引用时会引发异常,并试图将其推迟:

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,42]
Message: The entity "copy" was referenced, but not declared.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
    at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83)
    at org.simpleframework.xml.stream.StreamReader.read(StreamReader.java:110)
    at org.simpleframework.xml.stream.StreamReader.read(StreamReader.java:122)
    at org.simpleframework.xml.stream.StreamReader.next(StreamReader.java:94)
    at org.simpleframework.xml.stream.NodeReader.readElement(NodeReader.java:111)
    at org.simpleframework.xml.stream.NodeReader.readRoot(NodeReader.java:85)
    at org.simpleframework.xml.stream.NodeBuilder.read(NodeBuilder.java:84)
    at org.simpleframework.xml.stream.NodeBuilder.read(NodeBuilder.java:71)
    at org.simpleframework.xml.core.Persister.read(Persister.java:562)
    at org.simpleframework.xml.core.Persister.read(Persister.java:499)

Persister没有提供任何钩子来设置XMLInputFactory上的任何属性,如本文“Is there a Java XML API that can parse a document without resolving character entities?”中所推荐的那样

XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);

如何将IS_REPLACING_ENTITY_REFERENCES设置为false?

0 个答案:

没有答案