@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; }
xpathField.setNamespaceURIs( data.NAMESPACE ); if ( xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF ) { nodevalue = xpathField.valueOf( node );
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
private XPath createXPath(String xpathExpression) { XPath xpath = DocumentHelper.createXPath(xpathExpression); xpath.setNamespaceURIs(namespaces); return xpath; } }
private boolean dependencyHasMatchingGroupId(Element parentDependency) { XPath xpathGroupIdSelector = DocumentHelper.createXPath("./mvn4:groupId[text()=\"" + groupId + "\"]"); xpathGroupIdSelector.setNamespaceURIs(namespaceUris); return !xpathGroupIdSelector.selectNodes(parentDependency).isEmpty(); }
public String getResponseParameter(String response) { if (!response2parameter.containsKey(response)) { String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element/@name", response); XPath xpath = DocumentHelper.createXPath(query); xpath.setNamespaceURIs(ns2prefix); String param = xpath.valueOf(getDocument()); if (param.isEmpty()) { param = null; } response2parameter.put(response, param); } return response2parameter.get(response); }
/** * Executes the specified namespace aware XPath query as a multiple node query, returning the resulting list of nodes. */ @SuppressWarnings("unchecked") public static List<Node> selectNodes(Node node, String xpathQuery, Map<String, String> namespaceUris) { XPath xpath = DocumentHelper.createXPath(xpathQuery); xpath.setNamespaceURIs(namespaceUris); return xpath.selectNodes(node); }
private List<Node> findNodesMatchingInDoc(Document pomXml, String xpath) { XPath xpathForPluginManagement = pomXml.createXPath(xpath); xpathForPluginManagement.setNamespaceURIs(namespaceUris); return xpathForPluginManagement.selectNodes(pomXml); }
public String getDatatype(String method, String param) { String key = method + "." + param; if (!method2datatype.containsKey(key)) { String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element[@name='%s']/@type", method, param); XPath xpath = DocumentHelper.createXPath(query); xpath.setNamespaceURIs(ns2prefix); String datatype = xpath.valueOf(getDocument()); if (datatype.isEmpty()) { datatype = null; } method2datatype.put(key, datatype); } return method2datatype.get(key); }
public String getResponseParameter(String response) { if (!response2parameter.containsKey(response)) { String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element/@name", response); XPath xpath = DocumentHelper.createXPath(query); xpath.setNamespaceURIs(ns2prefix); String param = xpath.valueOf(getDocument()); if (param.isEmpty()) { param = null; } response2parameter.put(response, param); } return response2parameter.get(response); }
public String getDatatype(String method, String param) { String key = method + "." + param; if (!method2datatype.containsKey(key)) { String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element[@name='%s']/@type", method, param); XPath xpath = DocumentHelper.createXPath(query); xpath.setNamespaceURIs(ns2prefix); String datatype = xpath.valueOf(getDocument()); if (datatype.isEmpty()) { datatype = null; } method2datatype.put(key, datatype); } return method2datatype.get(key); }
/** * Executes the specified namespace aware XPath query as a single node query, returning the resulting single node. */ public static Node selectSingleNode(Node node, String xpathQuery, Map<String, String> namespaceUris) { XPath xpath = DocumentHelper.createXPath(xpathQuery); xpath.setNamespaceURIs(namespaceUris); return xpath.selectSingleNode(node); }
@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; }
private ImmutableMap<String, PageProperty> extractDetails(String macroBodyXhtml) throws IOException, DocumentException, ParserConfigurationException, SAXException { final Document macroBodyDoc = getMacroBodyDocument(macroBodyXhtml); final XPath xpath = macroBodyDoc.createXPath(XPATH_TBODY); xpath.setNamespaceURIs(NAMESPACE_MAP); final ImmutableMap<String, PageProperty> emptyMap = ImmutableMap.of(); final Element tableElement = (Element) xpath.selectSingleNode(macroBodyDoc); if (tableElement == null) return emptyMap; @SuppressWarnings("unchecked") final List<Element> rowElements = tableElement.elements("tr"); if (rowElements == null) return emptyMap; return loadDetailPairsFromTableRows(rowElements); }
@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; }
/** * Given a GTMS system element <system id="asterisk">...</system> returns the associated system * type. * * @param element of the form <system id="asterisk">...</system>. * @return system type. */ public static GtmsSystemType getSystemFromElement(Element element) { GtmsSystemType result = null; XPath xpath = DocumentHelper.createXPath("//gtx:system"); xpath.setNamespaceURIs(XmlUtil.getGtxNamespaceMap()); Node node = xpath.selectSingleNode(element); if (node != null) { String system = ((Element) node).attributeValue("id"); try { GtmsSystemType.valueOf(system); } catch (Exception e) { e.printStackTrace(); } } return result; }
namespaceMap.put("dc", "http://purl.org/dc/elements/1.1/"); XPath xpath = document.createXPath("//rdf:Description"); xpath.setNamespaceURIs(namespaceMap); Node node = xpath.selectSingleNode(lexicon); if (node != null) {
public void testURIMap() throws Exception { Map<String, String> uris = new HashMap<String, String>(); uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"); uris.put("m", "urn:xmethodsBabelFish"); String path = "/SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish"; XPath xpath = document.createXPath(path); xpath.setNamespaceURIs(uris); Node babelfish = xpath.selectSingleNode(document); // log( "Found: " + babelfish ); assertNotNull("Found valid node", babelfish); }