Code example for XPath

Methods: evaluate, setNamespaceContext

0
            throws XPathExpressionException, StreamException { 
        IAbstractFile file = getManifest(projectFolder);
        if (file != null) {
            return getPackage(file);
        } 
 
        return null; 
    } 
 
    /** 
     * Returns the package for a given manifest. 
     * @param manifestFile the manifest to parse. 
     * @return the package info or null (or empty) if not found. 
     * @throws XPathExpressionException 
     * @throws StreamException If any error happens when reading the manifest. 
     */ 
    public static String getPackage(IAbstractFile manifestFile)
            throws XPathExpressionException, StreamException { 
        XPath xPath = AndroidXPathFactory.newXPath();
 
        return xPath.evaluate(
                "/"  + NODE_MANIFEST +
                "/@" + ATTRIBUTE_PACKAGE,
                new InputSource(manifestFile.getContents()));
    }