/** * Construct an XPath expression from a given string. * * @param xpathExpr the string representation of the XPath expression. * @throws JaxenException if there is a syntax error while parsing the expression */ public AXIOMXPath(String xpathExpr) throws JaxenException { super(xpathExpr, new DocumentNavigator()); }
private static List<OMElement> evaluateXPathToElements(String expression, OMElement root) throws Exception { String[] nsPrefixes = wsdlPrefixes; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < nsPrefixes.length; j ++) { xpathExpression.addNamespace(nsPrefixes[j++], nsPrefixes[j]); } return (List<OMElement>)xpathExpression.selectNodes(root); }
/** * Returns the Axiom xpath. * * @param expression Xpath expression * @return Axiom xpath is returned */ public AXIOMXPath getXpathResult(String expression) throws JaxenException { return new AXIOMXPath(expression); }
public OMElement getSection(String sectionName) throws XdsInternalException { AXIOMXPath xpathExpression; try { xpathExpression = new AXIOMXPath("//*[local-name()='" + sectionName + "']"); List <OMElement> y = (List <OMElement>) xpathExpression.selectNodes(root); OMElement x = (OMElement) xpathExpression.selectSingleNode(root); return x; } catch (JaxenException e) { throw new XdsInternalException("Error extracting section " + sectionName + " from log output", e); } }
private String hl7Time(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Time"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception { AXIOMXPath xpath = new AXIOMXPath(xpathExpression); if (nsURI != null) { SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace(null, nsURI); xpath.setNamespaceContext(nsContext); } return xpath.selectNodes(element); }
OMElement documentElement = new StAXOMBuilder(inStreamToXML).getDocumentElement(); AXIOMXPath xpathExpression = new AXIOMXPath ("/demo"); List nodeList = (OMNode)xpathExpression.selectNodes(documentElement);
/** * Create an instance of EvaluatableSegment. * * @param name Name of segment. * @param expression Expression that needs evaluating to retrieve the value of segment. * @throws JaxenException on expression evalution error. */ protected EvaluatableSegment(String name, String expression) throws JaxenException { super(name); xpathProcessor = new AXIOMXPath(getNormalizedExpression(expression)); xpathProcessor.addNamespace(NAMESPACE_PREFIX, NAMESPACE_URL); }
private AXIOMXPath getAXIOMXPath( XPath xpath ) throws JaxenException { AXIOMXPath compiledXPath = new AXIOMXPath( xpath.getXPath() ); compiledXPath.setNamespaceContext( xpath.getNamespaceContext() ); return compiledXPath; }
@Override public String evaluate(OMElement message) throws JaxenException { String value = ""; OMElement element = (OMElement)xpathProcessor.selectSingleNode(message); if (element != null) { value = element.getText(); } return value; } }
/** * Construct an XPath expression from a given string and initialize its * namespace context based on a given element. * * @param element The element that determines the namespace context of the * XPath expression. See {@link #addNamespaces(OMElement)} * for more details. * @param xpathExpr the string representation of the XPath expression. * @throws JaxenException if there is a syntax error while parsing the expression * or if the namespace context could not be set up */ public AXIOMXPath(OMElement element, String xpathExpr) throws JaxenException { this(xpathExpr); addNamespaces(element); }
/** * Retrieves the string-value of an element node. This may be the empty string if the element is * empty, but must not be null. * * @param object the comment node. * @return Returns the string-value of the node. */ public String getElementStringValue(Object object) { if (isElement(object)) { return getStringValue((OMElement) object, new StringBuffer()) .toString(); } return null; }
/** * Retrieves an <code>Iterator</code> matching the <code>attribute</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 attribute axis are not supported by * this object model */ public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException { if (isElement(contextNode)) { return ((OMElement) contextNode).getAllAttributes(); } else { return JaxenConstants.EMPTY_ITERATOR; } }
@SuppressWarnings("unchecked") public static List<OMElement> evaluateXPathToElements(String expression, OMElement root) throws JaxenException { String[] wsdlPrefixes = { "wsdl", "http://schemas.xmlsoap.org/wsdl/", "wsdl2", "http://www.w3.org/ns/wsdl", "xsd", "http://www.w3.org/2001/XMLSchema", "soap", "http://schemas.xmlsoap.org/wsdl/soap/", "soap12", "http://schemas.xmlsoap.org/wsdl/soap12/", "http", "http://schemas.xmlsoap.org/wsdl/http/", }; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < wsdlPrefixes.length; j++) { xpathExpression.addNamespace(wsdlPrefixes[j++], wsdlPrefixes[j]); } return (List<OMElement>) xpathExpression.selectNodes(root); }
private String site(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Site"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
/** * This method provides AXIOMPath respective to the given Xpath. * * @param XpathString Xpath. * @return AXIOMPath. * @throws GovernanceException Throws when an exception occurs while getting value for the xPath. */ private static AXIOMXPath getAxiomPath(String XpathString) throws GovernanceException { try { return new AXIOMXPath(XpathString); } catch (JaxenException e) { throw new GovernanceException("Error while getting value relevant to Xpath: " + XpathString, e); } }
@Override public String evaluate(OMElement message) throws JaxenException { String value = ""; OMAttribute attribute = (OMAttribute)xpathProcessor.selectSingleNode(message); if (attribute != null) { value = attribute.getAttributeValue(); } return value; } }
public static List<OMAttribute> evaluateXPathToAttributes(String expression, OMElement root) throws Exception { String[] nsPrefixes = wsdlPrefixes; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < nsPrefixes.length; j ++) { xpathExpression.addNamespace(nsPrefixes[j++], nsPrefixes[j]); } List<OMAttribute> omElements = (List<OMAttribute>) xpathExpression.selectNodes(root); if (omElements == null) { return Collections.emptyList(); } return omElements; }
import org.apache.axiom.om.OMElement; import org.apache.axiom.om.xpath.AXIOMXPath; import org.jaxen.JaxenException; public String hello(OMElement xmlElement) { try { AXIOMXPath someXPath = new AXIOMXPath("//root/child"); String str = ((OMElement)someXPath.selectSingleNode(node)).getText(); } catch (JaxenException e) { e.printStackTrace(); } }
public static List<OMElement> evaluateXPathToElements(String expression, OMElement root) throws Exception { String[] nsPrefixes = wsdlPrefixes; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < nsPrefixes.length; j ++) { xpathExpression.addNamespace(nsPrefixes[j++], nsPrefixes[j]); } List<OMElement> omElements = (List<OMElement>) xpathExpression.selectNodes(root); if (omElements == null) { return Collections.emptyList(); } return omElements; }