I want to create w3c Document using StAXOMBuilder class in Axiom. 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. But when invoked it gives the error "The method createDocument() is undefined for the type StAXOMBuilder "
How to fix this?
The correct way to create a DOM Document
instance with Axiom is as follows. First, use OMAbstractFactory#getMetaFactory(String)
to get an OMMetaFactory
for the Axiom implementation that supports DOM. You do that by passing OMAbstractFactory.FEATURE_DOM
to that method. You then have two possibilities:
OMMetaFactory
to DOMMetaFactory
and use the JAXP/DOM compatible methods defined by that interface.OMDocument
and cast it to a 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.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.