[英]Can't invoke the protected method in StAXOMBuilder() class
I want to create w3c Document using StAXOMBuilder class in Axiom. 我想使用Axiom中的StAXOMBuilder类创建w3c文档。 And there is a method which can be used to achieve that task.
有一种方法可用于完成该任务。
OMElement documentElement = new StAXOMBuilder("resources/test.xml").getDocumentElement();
XMLStreamReader llomReader = documentElement.getXMLStreamReader();
OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
StAXOMBuilder doomBuilder = new StAXOMBuilder(doomFactory, llomReader);
Document doc = doomBuilder.createDocument();
createDocument method is available in STAXOMBuilder Class as a protected method. 在STAXOMBuilder类中可以使用createDocument方法作为受保护的方法。 But when invoked it gives the error "The method createDocument() is undefined for the type StAXOMBuilder "
但是,当调用它时会出现错误“对于类型为StAXOMBuilder的方法createDocument()未定义”
How to fix this? 如何解决这个问题?
Following method worked for me. 以下方法对我有用。 Thanks to Andreas.
感谢Andreas。
OMMetaFactory omMetaFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
OMFactory omFac = omMetaFactory.getOMFactory();
OMXMLParserWrapper wrapper = OMXMLBuilderFactory.createOMBuilder(omFac, new FileInputStream("resources/test.xml")) ;
Document doc = (Document) wrapper.getDocument();
为了能够调用类的protected
方法,您的类应该是StAXOMBuilder
子类,或者应位于同一包中。
The correct way to create a DOM Document
instance with Axiom is as follows. 使用Axiom创建DOM
Document
实例的正确方法如下。 First, use OMAbstractFactory#getMetaFactory(String)
to get an OMMetaFactory
for the Axiom implementation that supports DOM. 首先,使用
OMAbstractFactory#getMetaFactory(String)
为支持DOM的Axiom实现获取OMMetaFactory
。 You do that by passing OMAbstractFactory.FEATURE_DOM
to that method. 您可以通过将
OMAbstractFactory.FEATURE_DOM
传递给该方法来实现。 You then have two possibilities: 然后,您有两种可能性:
OMMetaFactory
to DOMMetaFactory
and use the JAXP/DOM compatible methods defined by that interface. OMMetaFactory
为DOMMetaFactory
并使用该接口定义的JAXP / DOM兼容方法。 OMDocument
and cast it to a Document
. OMDocument
并将其转换为Document
。 In particular, if you want to parse an existing document, use one of the methods in OMXMLBuilderFactory
that takes an OMMetaFactory
or OMFactory
argument so that Axiom will use the DOM compatible implementation retrieved earlier. OMXMLBuilderFactory
中带有OMMetaFactory
或OMFactory
参数的方法之一,以便Axiom将使用之前检索的DOM兼容实现。 Note that DOOMAbstractFactory
is deprecated and that StAXOMBuilder
is considered an internal implementation class (as the package name org.apache.axiom.om.impl.builder
implies) that should not be used directly. 请注意,不赞成使用
DOOMAbstractFactory
,并且StAXOMBuilder
将StAXOMBuilder
视为内部实现类(如包名称org.apache.axiom.om.impl.builder
所暗示),不应直接使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.