For IntelliJ IDEA and
Android Studio


private void myMethod () {XPath x =
String xpathExpression;DocumentHelper.createXPath(xpathExpression)
DocumentFactory documentFactory;documentFactory.createXPath(xpathExpression)
DocumentHelper documentHelper;documentHelper.getDocumentFactory().createXPath(xpathExpression)
- AI code suggestions by Codota
}
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
@SuppressWarnings( "unchecked" ) private boolean applyXPath() { try { XPath xpath = data.document.createXPath( data.PathValue ); if ( meta.isNamespaceAware() ) { xpath = data.document.createXPath( addNSPrefix( data.PathValue, data.PathValue ) ); xpath.setNamespaceURIs( data.NAMESPACE ); } // get nodes list data.an = xpath.selectNodes( data.document ); data.nodesize = data.an.size(); data.nodenr = 0; } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "GetXMLData.Log.ErrorApplyXPath", e.getMessage() ) ); return false; } return true; }
@Override public boolean matches(Object o) { if (o instanceof String) { String input = (String) o; try { Document document = DocumentHelper.parseText(input); XPath xPath = document.createXPath(this.expression); if (this.namespaces != null) xPath.setNamespaceURIs(this.namespaces.build()); String evaluatedValue = xPath.valueOf(document); return !xPath.selectNodes(document).isEmpty() && value.matches(evaluatedValue); } catch (DocumentException e) { throw new RuntimeException(e.getMessage(), e); } } System.err.println("Incorrect input"); return false; }
/** * Search the specified document for Nodes corresponding to the xpath Keep * in mind that you have to use xmpp namespace for searching * Predefined namespaces: * jabber:iq:roster //roster:* * jabber:iq:register //register:* * http://jabber.org/protocol/disco#info //disco/* * e.g * '//roster:features' * * @param doc * document * @param xpath * with roster namespace for searching in query nodes * @return list of nodes found by xpath expression */ @SuppressWarnings("unchecked") public static List<Node> findNodesInDocument(Document doc, String xpath) { Map<String, String> namespaceUris = new HashMap<String, String>(); namespaceUris.put("roster", "jabber:iq:roster"); namespaceUris.put("discoitems", "http://jabber.org/protocol/disco#items"); namespaceUris.put("register", "jabber:iq:register"); namespaceUris.put("disco", "http://jabber.org/protocol/disco#info"); XPath xPath = DocumentHelper.createXPath(xpath); xPath.setNamespaceURIs(namespaceUris); return xPath.selectNodes(doc); }
@Override public boolean matches(Object o) { if (o instanceof String) { String input = (String) o; try { Document document = DocumentHelper.parseText(input); XPath xPath = document.createXPath(this.expression); if (this.contexts != null) { xPath.setNamespaceURIs(this.contexts.build()); } List<Node> list = xPath.selectNodes(document); boolean contains = !list.isEmpty(); return contains; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } return false; }
Map<String,String> uris = new HashMap<String,String>(); uris.put(ATOM_NS_PREFIX, ATOM_NS_URI); xpath.setNamespaceURIs(uris);
Map<String,String> uris = new HashMap<String,String>(); uris.put("ws", "http://www.alfresco.org/webscript/1.0"); xpath.setNamespaceURIs(uris); List nodes = xpath.selectNodes(rootElement); if (nodes.size() == 0)
xpathField.setNamespaceURIs( data.NAMESPACE ); if ( xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF ) { nodevalue = xpathField.valueOf( node );
Map<String,String> uris = new HashMap<String,String>(); uris.put("ws", "http://www.alfresco.org/webscript/1.0"); xpath.setNamespaceURIs(uris); List nodes = xpath.selectNodes(rootElement); if (nodes.size() == 0)