Java XPath Evaluate evaluate(File xmlFile, String xPathExpression)

Here you can find the source of evaluate(File xmlFile, String xPathExpression)

Description

evaluate

License

Open Source License

Declaration

public static String evaluate(File xmlFile, String xPathExpression) 

Method Source Code


//package com.java2s;
/*//from ww  w.j  av  a2 s .  co m
* Copyright (c) 2010-2012 Research In Motion Limited. All rights reserved.
*
* This program and the accompanying materials are made available
* under  the terms of the Apache License, Version 2.0,
* which accompanies this distribution and is available at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 
*/

import java.io.File;
import java.io.FileInputStream;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.xml.sax.InputSource;

public class Main {
    public static String evaluate(File xmlFile, String xPathExpression) {
        String result = null;

        try {
            XPathFactory factory = XPathFactory.newInstance();
            XPath xPath = factory.newXPath();
            result = xPath.evaluate(xPathExpression, new InputSource(new FileInputStream(xmlFile)));
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }

        return result;
    }
}

Related

  1. asByte(String expression, Node node)
  2. asByte(String expression, Node node)
  3. convertToXpath(String qname)
  4. evaluate(Document doc)
  5. evaluate(Node node, XPathExpression expression)
  6. evaluate(Object obj, String xpathExpression, QName qName)
  7. evaluate(String path, Node node)
  8. evaluate(XPath xpath, String base, String path, Document document)