Java 8 XPathExpression - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 XPathExpression class.

This code example shows how to use the following methods:evaluate
  } 
 
  @Override 
  public String getPackage() {
    try { 
      return (String) packageExpression.evaluate(doc, XPathConstants.STRING);
    } catch (XPathExpressionException e) {
      throw Throwables.propagate(e);
    } 
  } 
 
  /** 
   * This allows querying the AndroidManifest for e.g. attributes like android:name using XPath 
   */ 
  private static NamespaceContext androidNamespaceContext = new NamespaceContext() {
    @Override 
    public Iterator<String> getPrefixes(String namespaceURI) { 
      throw new UnsupportedOperationException(); 
    } 
 
6
CodeRank
This code example shows how to use the following methods:evaluate
                    .get(xPathExpression);
            if (expr == null) {
                expr = XPATH.compile(xPathExpression);
                COMPILED_EXPRESSION_CACHE.put(xPathExpression, expr);
            } 
            attr = (Node) expr.evaluate(element, XPathConstants.NODE);
        } 
        catch (final XPathExpressionException e) {
            throw new IllegalArgumentException(
                    "Unable evaluate xpath expression", e);
        } 
        return attr;
    } 
 
    /** 
     * Searches the given parent element for a child element matching the given 
     * XPath expression. Please note that the XPath parser used is NOT namespace 
     * aware. So if you want to find an element 
     * <code>&lt;beans&gt;&lt;sec:http&gt;</code>, you need to use the following 
     * XPath expression '/beans/http'. 
6
CodeRank
This code example shows how to use the following methods:evaluate
    XPath xpath = factory.newXPath();
    Object result;
    try { 
      XPathExpression expr =
        xpath.compile("/stratcon/database/dbconfig/" + param + "/text()");
      result = expr.evaluate(doc, XPathConstants.NODESET);
    } 
    catch(XPathExpressionException e) {
      System.err.println("Bad expression: " + e.getMessage());
      return null; 
    } 
    NodeList nodes = (NodeList) result;
    if(nodes.getLength() > 0) {
      return nodes.item(nodes.getLength() -1).getNodeValue();
    } 
    return null; 
  } 
  public String getBroker() {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
6
CodeRank
This code example shows how to use the following methods:evaluate
        } 
        try { 
            XPathFactory xPathFactory = XPathFactory.newInstance();
            XPath xpath = xPathFactory.newXPath();
            XPathExpression fileExp = xpath.compile("file/text()");
            String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
            if (fileStr == null || fileStr.isEmpty()) {
                throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
            } 
 
            InputStream in = support.getInputStream(fileStr);
            GpxImporter.GpxImporterData importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), null, progressMonitor);
 
            support.addPostLayersTask(importData.getPostLayerTask());
            return importData.getGpxLayer();
 
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        } 
    } 
5
CodeRank
This code example shows how to use the following methods:evaluate
        } 
        try { 
            XPathFactory xPathFactory = XPathFactory.newInstance();
            XPath xpath = xPathFactory.newXPath();
            XPathExpression fileExp = xpath.compile("file/text()");
            String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
            if (fileStr == null || fileStr.isEmpty()) {
                throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
            } 
 
            OsmImporter importer = new OsmImporter();
            InputStream in = support.getInputStream(fileStr);
            OsmImporter.OsmImporterData importData = importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), progressMonitor);
 
            support.addPostLayersTask(importData.getPostLayerTask());
            return importData.getLayer();
 
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        } 
5
CodeRank
This code example shows how to use the following methods:evaluate
			try { 
				XPathFactory xPathfactory = XPathFactory.newInstance();
				XPath xpath = xPathfactory.newXPath();
				XPathExpression expr = xpath
						.compile("/response/lst[@name='status']/lst/date[@name='startTime']/text()");
				return (String) expr.evaluate(dom, XPathConstants.STRING);
			} catch (XPathExpressionException e) {
				throw new OpsException("Error reading value from XML", e);
			} 
		} 
	} 
 
	public void reload() throws OpsException { 
		execute("RELOAD"); 
	} 
 
	public SolrCoreStatus getStatus() throws OpsException { 
		CurlResult result = execute("STATUS");
		String xml = result.getBody();
		boolean namespaceAware = false;
5
CodeRank
This code example shows how to use the following methods:evaluate
 
    private String transformResponseToMessage(DOMSource response) throws Exception {
        Document document = (Document) response.getNode();
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression expression = xpath.compile("//return/text()");
        String result = (String) expression.evaluate(document, XPathConstants.STRING);
        return result;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:evaluate
         
        final XPathFactory xPathFactory = XPathFactory.newInstance();
        final XPath xPath = xPathFactory.newXPath();
        final XPathExpression xPathExpression = xPath.compile("//*[@ID='11']");
         
        final Node node = (Node)xPathExpression.evaluate(testDoc, XPathConstants.NODE);
         
        final XmlUtilitiesImpl xmlUtilities = new XmlUtilitiesImpl();
        final String nodePath = xmlUtilities.getUniqueXPath(node);
         
        assertEquals("/layout/folder[2]/folder[3]", nodePath);
    } 
 
    private Document loadTestDocument() throws IOException, SAXException {
        final InputStream testDocStream = this.getClass().getResourceAsStream("/org/jasig/portal/xml/xmlUtilitiesTest.xml");
        final Document testDoc = DocumentFactory.getDocumentFromStream(testDocStream, "xmlUtilitiesTest.xml");
        IOUtils.closeQuietly(testDocStream);
        return testDoc;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:evaluate
	} 
 
	/** Eval to a NodeList */ 
	@Override 
	NodeList eval(XMLResource resource) throws Exception {
		NodeList retVal = (NodeList) xPathExpression.evaluate(resource.doc(), XPathConstants.NODESET);
		return retVal;
	} 
	 
	/** Evaluate the XPath on an XMLResource and convert the result into aReturnType. 
	 *  
	 * @param <T> the expected type of the result 
	 * @param resource 
	 * @param aReturnType  
	 * @return 
	 * @throws Exception 
	 */ 
	public <T> T eval(XMLResource resource, Class<T>aReturnType) throws Exception {
		T retVal = (T) xPathExpression.evaluate(resource.doc(), getConstant(aReturnType));
		return retVal;
5
CodeRank
This code example shows how to use the following methods:evaluate
 
	public Node getNode(Node start, String strXPath) {
		XPathExpression exp = getExpression(strXPath);
 
		try { 
			return (Node) exp.evaluate(start, XPathConstants.NODE);
		} catch (XPathExpressionException e) {
			throw new RuntimeException("GetNode failed", e);
		} 
	} 
 
	public Node getNode(String strXPath) {
		return getNode(doc.getDocumentElement(), strXPath);
	} 
 
	public NodeList getNodes(Node start, String strXPath) {
		XPathExpression exp = getExpression(strXPath);
 
		try { 
			return (NodeList) exp.evaluate(start, XPathConstants.NODESET);
5
CodeRank

Related Java 8 XPathExpression Questions & Answers:

See Code Examples for Java 8 XPathExpression Methods: