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
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 toOMElementImpl
is useless because thegetText
method is defined by theOMElement
interface.To answer the question, yes,
OMElement
extendsOMNode
, 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.).