public static List<OMElement> getElements(OMElement doc, String xpath) throws Exception { XPathEvaluator eval = new XPathEvaluator(); List<OMNode> node_list = eval.evaluateXpath(xpath, doc, null); List<OMElement> ele_list = new ArrayList<OMElement>(); for (Iterator<?> it=node_list.iterator(); it.hasNext(); ) { OMNode node = (OMNode) it.next(); if (! (node instanceof OMElement)) continue; OMElement ele = (OMElement) node; ele_list.add(ele); } return ele_list; }
public static String getElementValue(OMElement doc, String xpath) throws Exception { XPathEvaluator eval = new XPathEvaluator(); List<OMNode> node_list = eval.evaluateXpath(xpath, doc, null); for (Iterator<?> it=node_list.iterator(); it.hasNext(); ) { OMNode node = (OMNode) it.next(); if (! (node instanceof OMElement)) continue; OMElement ele = (OMElement) node; return ele.getText(); } throw new Exception("Path " + xpath + " not found"); }
public static String getAttributeValue(OMElement doc, String xpath) throws Exception { XPathEvaluator eval = new XPathEvaluator(); List<OMNode> node_list = eval.evaluateXpath(xpath, doc, null); for (Iterator<?> it=node_list.iterator(); it.hasNext(); ) { OMAttribute attr = (OMAttribute) it.next(); return attr.getAttributeValue(); } throw new Exception("Path " + xpath + " not found"); }
public static List<String> getAttributeValues(OMElement doc, String xpath) throws Exception { List<String> values = new ArrayList<String>(); XPathEvaluator eval = new XPathEvaluator(); List<OMNode> node_list = eval.evaluateXpath(xpath, doc, null); for (Iterator<?> it=node_list.iterator(); it.hasNext(); ) { OMAttribute attr = (OMAttribute) it.next(); values.add(attr.getAttributeValue()); } if (values.size() == 0) throw new Exception("No Values"); return values; }
@Override public boolean accept(NotificationMessage message) { boolean result = true; try { OMElement messageElement = WsnHelper .notificationMessageToOM(message); OMDocument document = AxiomHelper.createEmptyDocument(); document.addChild(messageElement); XPathEvaluator eval = new XPathEvaluator(); List list = eval.evaluateXpath(xpathPattern, document, null); // accept the message only if the evaluation returns a non empty // list result = (list.size() > 0); } catch (Exception e) { result = false; } return result; } }
er.registerValidator(this); XPathEvaluator eval = new XPathEvaluator(); try { @SuppressWarnings("unchecked") List<OMNode> node_list = eval.evaluateXpath("//*[local-name()='Document']", xml, null); for (OMNode node : node_list) { OMElement docEle;