当前位置: 首页>>代码示例>>Java>>正文


Java XPath.evaluate方法代码示例

本文整理汇总了Java中javax.xml.xpath.XPath.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.evaluate方法的具体用法?Java XPath.evaluate怎么用?Java XPath.evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.xpath.XPath的用法示例。


在下文中一共展示了XPath.evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVersion

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * Returns the version
 * 
 * @return String
 */
public static String getVersion() {
    String jarImplementation = VISNode.class.getPackage().getImplementationVersion();
    if (jarImplementation != null) {
        return jarImplementation;
    }
    String file = VISNode.class.getResource(".").getFile();
    String pack = VISNode.class.getPackage().getName().replace(".", "/") + '/';
    File pomXml = new File(file.replace("target/classes/" + pack, "pom.xml"));
    if (pomXml.exists()) {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document = builder.parse(new InputSource(new FileReader(pomXml)));
            XPath xPath = XPathFactory.newInstance().newXPath();
            return (String) xPath.evaluate("/project/version", document, XPathConstants.STRING);
        } catch (IOException | ParserConfigurationException | XPathExpressionException | SAXException e) { }
    }
    return "Unknown version";
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:25,代码来源:VersionFinder.java

示例2: findElementValues

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private List<ElementValue> findElementValues(ElementValue pev, String path) {
    List<ElementValue> result = new ArrayList<>();
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        NodeList list = (NodeList) xpath.evaluate(path, pev.getElement(), XPathConstants.NODESET);
        for (int i = 0; i < list.getLength(); i++) {
            result.add(new ElementValue((Element) list.item(i), Type.OK));
        }
    } catch (XPathExpressionException ex) {
    }
    return result;
}
 
开发者ID:The-Retired-Programmer,项目名称:nbreleaseplugin,代码行数:13,代码来源:Pom.java

示例3: eval

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public boolean eval() throws BuildException {
    if (nullOrEmpty(fileName)) {
        throw new BuildException("No file set");
    }
    File file = new File(fileName);
    if (!file.exists() || file.isDirectory()) {
        throw new BuildException(
                "The specified file does not exist or is a directory");
    }
    if (nullOrEmpty(path)) {
        throw new BuildException("No XPath expression set");
    }
    XPath xpath = XPathFactory.newInstance().newXPath();
    InputSource inputSource = new InputSource(fileName);
    Boolean result = Boolean.FALSE;
    try {
        result = (Boolean) xpath.evaluate(path, inputSource,
                XPathConstants.BOOLEAN);
    } catch (XPathExpressionException e) {
        throw new BuildException("XPath expression fails", e);
    }
    return result.booleanValue();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:XPathCondition.java

示例4: removeWhitespace

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private void removeWhitespace(Document document) throws XPathExpressionException {
	document.normalize();
	XPath xPath = XPathFactory.newInstance().newXPath();
	NodeList nodeList = (NodeList) xPath.evaluate("//text()[normalize-space()='']",
			document,
			XPathConstants.NODESET);

	for (int i = 0; i < nodeList.getLength(); ++i) {
		Node node = nodeList.item(i);
		node.getParentNode().removeChild(node);
	}
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:13,代码来源:QrdaGenerator.java

示例5: doPopulateUnapproved

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private void doPopulateUnapproved(Map<String, ModuleInfo> moduleRATInfo, Element rootElement, XPath path) throws XPathExpressionException {
    NodeList evaluate = (NodeList) path.evaluate("descendant::resource[license-approval/@name=\"false\"]", rootElement, XPathConstants.NODESET);
    for (int i = 0; i < evaluate.getLength(); i++) {
        String resources = relativize(evaluate.item(i).getAttributes().getNamedItem("name").getTextContent());
        String moduleName = getModuleName(resources);
        if (!moduleRATInfo.containsKey(moduleName)) {
            moduleRATInfo.get(NOT_CLUSTER).addUnapproved(resources);
        } else {
            moduleRATInfo.get(moduleName).addUnapproved(resources);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:RatReportTask.java

示例6: readExampleDefine

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public static ExampleDefine readExampleDefine(InputStream in) throws Exception {
	   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();  
	   DocumentBuilder dbd = dbf.newDocumentBuilder();  
	   Document doc = dbd.parse(in);  
	   XPathFactory f = XPathFactory.newInstance();  
	   XPath path = f.newXPath();  	   
	   Node scriptNode= (Node)path.evaluate("example/script", doc,XPathConstants.NODE);
	   String script = scriptNode.getTextContent().trim();
	   Node contextNode= (Node)path.evaluate("example/context", doc,XPathConstants.NODE);
	   String context =  contextNode.getTextContent().trim();
	   return new ExampleDefine(script,context);
}
 
开发者ID:alibaba,项目名称:QLExpress,代码行数:13,代码来源:ReadExample.java

示例7: compare

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * Compares AXI component against corresponding DOM element.
 */
private boolean compare(AXIComponent axiNode) {        
    FileUtil util = FileUtil.getInstance();
    try {
        InputSource inputSource = util.openFile(expectedFileURL);
        if(inputSource == null) {
            success = false;
            return false;
        }
        String expression = getExpression(axiNode);
        XPath xpath = XPathFactory.newInstance().newXPath();
        Node domNode = (Node) xpath.evaluate(expression, inputSource, XPathConstants.NODE);
        if(!axiNode.toString().equals(domNode.getNodeName())) {
            success = false;
            errorMessage = "Expected AXI node " + axiNode + ", but found DOM node " + domNode.getNodeName();
            return false;
        }
                    
        if(!compareChildren(axiNode, domNode)) {
            return false;
        }
        
    } catch(Exception ex) {
        ex.printStackTrace();
        success = false;
        errorMessage = "Exception: " + ex.getMessage();
        return false;
    } finally {
        util.closeFile();
    }
    
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:ModelValidator.java

示例8: findElementValue

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private ElementValue findElementValue(ElementValue pev, String path, String defaultvalue) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        Element el = (Element) xpath.evaluate(path, pev.getElement(), XPathConstants.NODE);
        return el == null
                ? new ElementValue(defaultvalue)
                : new ElementValue(el, pev.isInHerited() ? Type.INHERITED : Type.OK);
    } catch (XPathExpressionException ex) {
        return new ElementValue(defaultvalue);
    }
}
 
开发者ID:The-Retired-Programmer,项目名称:nbreleaseplugin,代码行数:12,代码来源:Pom.java

示例9: stringTag

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private String stringTag(
        final Element element,
        final XPath xpath,
        final String tagName
) throws XPathExpressionException {
    return (String) xpath.evaluate(tagName + "/text()", element, STRING);
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:8,代码来源:PersistenceUnitDiscovery.java

示例10: getNodeList

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * Hulpmethode om de nodes uit een node te halen middels xpath.
 * @param locatie de locatie van de node als xpath.
 * @param xPath een XPath instantie
 * @param node de basis node
 * @return de text
 */
protected static NodeList getNodeList(final String locatie, final XPath xPath, final Node node) {
    try {
        return (NodeList) xPath.evaluate(locatie, node, XPathConstants.NODESET);
    } catch (final XPathExpressionException e) {
        LOGGER.error("XPath voor node list kon niet worden geëvalueerd voor locatie {}.", locatie);
        throw new UnsupportedOperationException(e);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:16,代码来源:AbstractDienstVerzoekParser.java

示例11: findElement

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private Element findElement(ElementValue pev, String path) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        return (Element) xpath.evaluate(path, pev.getElement(), XPathConstants.NODE);
    } catch (XPathExpressionException ex) {
        return null;
    }
}
 
开发者ID:The-Retired-Programmer,项目名称:nbreleaseplugin,代码行数:9,代码来源:Pom.java

示例12: getVersionElement

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private Element getVersionElement(Document doc) throws MojoExecutionException {
    XPath xPath = XPathFactory.newInstance().newXPath();

    try {
        NodeList nodes = ((NodeList) xPath.evaluate("/project/version", doc.getDocumentElement(), XPathConstants.NODESET));
        if (nodes.getLength() == 0) {
            return null;
        }

        return (Element) nodes.item(0);

    } catch (XPathExpressionException e) {
        throw new MojoExecutionException("Failed to evaluate xpath expression", e);
    }
}
 
开发者ID:hbakkum,项目名称:resolve-parent-version-maven-plugin,代码行数:16,代码来源:ResolveParentVersionMojo.java

示例13: getAttributeQuery

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private Element getAttributeQuery(Document document) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    xpath.setNamespaceContext(context);

    return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:SoapMessageManagerTest.java

示例14: getXPathFromLastRESTResponse

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
@Then("get value from REST-XML response by '$xpath' and save to '$variable'")
public void getXPathFromLastRESTResponse(String xPath, String variable) throws IOException, SOAPException, ParserConfigurationException, SAXException, XPathExpressionException {
    Response response = getVariableValue(KEY);
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource source = new InputSource();
    source.setCharacterStream(new StringReader(response.getBody().asString()));
    Document doc = db.parse(source);
    XPath xpath = XPathFactory.newInstance().newXPath();
    Node node = (Node) xpath.evaluate(xPath, doc.getDocumentElement(), XPathConstants.NODE);
    assertNotNull("No element by Xpath: " + xPath + " was found", node);
    save(variable, node.getTextContent());
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:13,代码来源:RestXMLOnlySteps.java

示例15: hasVersionCode

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * Returns whether the version Code attribute is set in a given manifest.
 * @param manifestFile the manifest to check
 * @return true if the versionCode attribute is present and its value is not empty.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean hasVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    XPath xPath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = manifestFile.getContents();
        Object result = xPath.evaluate(
                "/"  + NODE_MANIFEST +
                "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
                ":"  + ATTRIBUTE_VERSIONCODE,
                new InputSource(is),
                XPathConstants.NODE);

        if (result != null) {
            Node node  = (Node)result;
            if (!node.getNodeValue().isEmpty()) {
                return true;
            }
        }
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }

    return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:38,代码来源:AndroidManifest.java


注:本文中的javax.xml.xpath.XPath.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。