/** * Construct an XPath expression from a given attribute. * The string representation of the expression is taken from the attribute * value, while the attribute's owner element is used to determine the * namespace context of the expression. * * @param attribute the attribute to construct the expression from * @throws JaxenException if there is a syntax error while parsing the expression * or if the namespace context could not be set up */ public AXIOMXPath(OMAttribute attribute) throws JaxenException { this(attribute.getOwner(), attribute.getAttributeValue()); }
/** * Returns the parent of the given context node. * <p> * The parent of any node must either be a document node or an element node. * * @param contextNode the context node * @return Returns the parent of the context node, or null if this is a document node. * @throws UnsupportedAxisException if the parent axis is not supported by the model * @see #isDocument * @see #isElement */ public Object getParentNode(Object contextNode) throws UnsupportedAxisException { if (contextNode == null || contextNode instanceof OMDocument) { return null; } else if (contextNode instanceof OMAttribute) { return ((OMAttribute) contextNode).getOwner(); } else if (contextNode instanceof OMNamespaceEx) { return ((OMNamespaceEx) contextNode).getParent(); } return ((OMNode) contextNode).getParent(); }
public QName[] getNodesAsQNames( OMElement contextNode, XPath xpath ) { QName[] values = null; List<?> nl = getNodes( contextNode, xpath ); if ( nl != null ) { values = new QName[nl.size()]; for ( int i = 0; i < nl.size(); i++ ) { Object node = nl.get( i ); QName value = null; if ( node instanceof OMText ) { value = ( (OMText) node ).getTextAsQName(); } else if ( node instanceof OMElement ) { OMElement element = (OMElement) node; value = element.resolveQName( element.getText() ); } else if ( node instanceof OMAttribute ) { OMAttribute attribute = (OMAttribute) node; value = attribute.getOwner().resolveQName( attribute.getAttributeValue() ); } else { String msg = "Unexpected node type '" + node.getClass() + "'."; throw new XMLParsingException( this, contextNode, msg ); } values[i] = value; } } else { values = new QName[0]; } return values; }
public QName getNodeAsQName( OMElement context, XPath xpath, QName defaultValue ) throws XMLParsingException { QName value = defaultValue; Object node = getNode( context, xpath ); if ( node != null ) { if ( node instanceof OMText ) { value = ( (OMText) node ).getTextAsQName(); } else if ( node instanceof OMElement ) { OMElement element = (OMElement) node; value = element.resolveQName( element.getText() ); } else if ( node instanceof OMAttribute ) { OMAttribute attribute = (OMAttribute) node; value = attribute.getOwner().resolveQName( attribute.getAttributeValue() ); } else { String msg = "Unexpected node type '" + node.getClass() + "'."; throw new XMLParsingException( this, context, msg ); } } return value; }
OMElement parentElement = ((OMAttribute)resultNode).getOwner(); if(parentElement.getAttributeValue(new QName("class")).equals(defaultLifecycleGeneratorClass)){ Iterator childrenIterator = parentElement.getParent().getChildrenWithLocalName("name");
/** * Retrieves an <code>Iterator</code> matching the <code>parent</code> XPath axis. * * @param contextNode the original context node * @return Returns an Iterator capable of traversing the axis, not null. * @throws UnsupportedAxisException if the semantics of the parent axis are not supported by * this object model */ public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException { if (contextNode instanceof OMNode) { return new SingleObjectIterator(((OMNode) contextNode).getParent()); } else if (contextNode instanceof OMNamespaceEx) { return new SingleObjectIterator( ((OMNamespaceEx) contextNode).getParent()); } else if (contextNode instanceof OMAttribute) { return new SingleObjectIterator( ((OMAttribute) contextNode).getOwner()); } return JaxenConstants.EMPTY_ITERATOR; }