Question

What are the differences and their usages between OMNode and OMElement in AXIOM ? I have implemented a XML parser and I used both of the objects in the implementation. Is the OMElement is a sub class of the OMNode ?

As an example both behaves in same way: Look at this

//OMElement
OMElement omElement = nodeElement;
String attributeValue = ((OMElementImpl) omElement).getText();

//OMNode
OMNode omNode = nodeElement;
String attributeValue = ((OMElementImpl) omNode).getText();

Both support for the casting and in the same way

Was it helpful?

Solution

First of all, your code refers to OMElementImpl. You shouldn't do that. As the name of the class (and also the name of the package that contains that class) indicates, this is an implementation class that should not be used directly in application code. Anyways, the cast to OMElementImpl is useless because the getText method is defined by the OMElement interface.

To answer the question, yes, OMElement extends OMNode, as you can see in the Javadoc:

http://ws.apache.org/axiom/apidocs/org/apache/axiom/om/OMElement.html

As the name indicates, OMElement represents an XML element. OMNode on the other hand is implemented by all Axiom classes that represent an XML information item that can be a child of another information item (such as a comment, text node, processing instruction, etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top