Package javax.xml.xpath

Examples of javax.xml.xpath.XPath.compile()


        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        if (xpathFilter.getNamespaceMap() != null) {
            xpath.setNamespaceContext(new XPathNamespaceContext(xpathFilter.getNamespaceMap()));
        }
        return xpath.compile(xpathFilter.getXPath());
    }

    private static class XPathNamespaceContext implements NamespaceContext {

        private final Map<String, String> prefix2Namespace;
View Full Code Here


            public String getNamespaceURI(String prefix) {
                return prefix2Namespace.get(prefix);
            }
        };
        xpath.setNamespaceContext(nc);
        XPathExpression expr = xpath.compile(xpathString);
        Object result = expr.evaluate(XmlSignatureHelper.newDocumentBuilder(true).parse(body), XPathConstants.NODE);
        assertNotNull("The xpath " + xpathString + " returned a null value", result);
        return result;
    }
View Full Code Here

            @Override
            public String getNamespaceURI(String prefix) {
                switch (prefix) {
                    case "scr":
                        try {
                            XPathExpression scrNamespace = xPath.compile("/*/namespace::*[name()='scr']");
                            Node node = (Node) scrNamespace.evaluate(dom, XPathConstants.NODE);
                            return node.getNodeValue();
                        } catch (XPathExpressionException e) {
                            // ignore
                            LOG.debug("Error evaluating xpath to obtain namespace prefix. This exception is ignored and using namespace: http://www.osgi.org/xmlns/scr/v1.1.0", e);
View Full Code Here

                return null;
            }
        });

        String propertyListExpression = String.format("/components/scr:component[@name='%s']/property", componentName);
        XPathExpression propertyList = xPath.compile(propertyListExpression);
        XPathExpression propertyName = xPath.compile("@name");
        XPathExpression propertyValue = xPath.compile("@value");
        NodeList nodes = (NodeList) propertyList.evaluate(dom, XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
View Full Code Here

            }
        });

        String propertyListExpression = String.format("/components/scr:component[@name='%s']/property", componentName);
        XPathExpression propertyList = xPath.compile(propertyListExpression);
        XPathExpression propertyName = xPath.compile("@name");
        XPathExpression propertyValue = xPath.compile("@value");
        NodeList nodes = (NodeList) propertyList.evaluate(dom, XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            result.put((String) propertyName.evaluate(node, XPathConstants.STRING), (String) propertyValue.evaluate(node, XPathConstants.STRING));
View Full Code Here

        });

        String propertyListExpression = String.format("/components/scr:component[@name='%s']/property", componentName);
        XPathExpression propertyList = xPath.compile(propertyListExpression);
        XPathExpression propertyName = xPath.compile("@name");
        XPathExpression propertyValue = xPath.compile("@value");
        NodeList nodes = (NodeList) propertyList.evaluate(dom, XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            result.put((String) propertyName.evaluate(node, XPathConstants.STRING), (String) propertyValue.evaluate(node, XPathConstants.STRING));
        }
View Full Code Here

    public String getStartTime() throws OpsException {
      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);
      }
View Full Code Here

    XPathFactory factory = XPathFactory.newInstance();
    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;
View Full Code Here

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    Object result;
    try {
      XPathExpression expr =
        xpath.compile("/stratcon/iep/broker/@adapter");
      result = expr.evaluate(doc, XPathConstants.NODESET);
    }
    catch(XPathExpressionException e) {
      System.err.println("Bad expression: " + e.getMessage());
      return null;
View Full Code Here

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    Object result;
    try {
      XPathExpression expr =
        xpath.compile("/stratcon/iep/mq/@type");
      result = expr.evaluate(doc, XPathConstants.NODESET);
    }
    catch(XPathExpressionException e) {
      System.err.println("Bad expression: " + e.getMessage());
      return null;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.