Package javax.xml.xpath

Examples of javax.xml.xpath.XPath


            CoverageScope scope) throws WSSecurityException {
       
        // XPathFactory and XPath are not thread-safe so we must recreate them
        // each request.
        final XPathFactory factory = XPathFactory.newInstance();
        final XPath xpath = factory.newXPath();
       
        if (namespaces != null) {
            xpath.setNamespaceContext(new MapNamespaceContext(namespaces));
        }
       
        // For each XPath
        for (String xpathString : xPaths) {
            // Get the matching nodes
            NodeList list;
            try {
                list = (NodeList)xpath.evaluate(
                        xpathString,
                        message.getSOAPPart().getEnvelope(),
                        XPathConstants.NODESET);
            } catch (XPathExpressionException e) {
                // The xpath's are not valid in the config.
View Full Code Here


      DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = domFactory.newDocumentBuilder();
      StringReader reader = new StringReader(error);
      Document doc = builder.parse(new InputSource(reader));
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      String method = (String) xpath
        .evaluate("/Error/@Method", doc, XPathConstants.STRING);
      String calaisRequestID = (String) xpath
        .evaluate("/Error/@calaisRequestID", doc, XPathConstants.STRING);
      String creationDate = (String) xpath
        .evaluate("/Error/@CreationDate", doc, XPathConstants.STRING);
      String calaisVersion = (String) xpath
        .evaluate("/Error/@CalaisVersion", doc, XPathConstants.STRING);
      String exception = (String) xpath
        .evaluate("/Error/Exception/text()", doc, XPathConstants.STRING);
      return new CalaisException(method, calaisRequestID, creationDate,
                                 calaisVersion, exception);
    } catch (Exception e) {
      throw new RuntimeException("Unable to parse exception", e);
View Full Code Here

    // Using XPath to get a single value from an metainfo file
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(stackMetainfoFile);
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();
    XPathExpression schemaPath = xpath.compile("/metainfo/schemaVersion[1]");

    String value = schemaPath.evaluate(doc).trim();
    if ( "".equals(value) || // If schemaVersion is not defined
            AmbariMetaInfo.SCHEMA_VERSION_LEGACY.equals(value)) {
      return AmbariMetaInfo.SCHEMA_VERSION_LEGACY;
View Full Code Here

            Entry entry = (Entry)feed.getEntries().get(0);
            String rateTable = entry.getSummary().getValue();

            Document doc = builder.parse(new ByteArrayInputStream(rateTable.getBytes()));
            Node node = doc.getDocumentElement();
            XPath path = XPathFactory.newInstance().newXPath();
            XPathExpression exp = path.compile("/TABLE/TR[TD[1]='" + currency.toUpperCase() + "']/TD[2]");
            Node rateNode = (Node)exp.evaluate(node, XPathConstants.NODE);
            double rate = Double.valueOf(rateNode.getTextContent().trim());
            System.out.println("Exchange rate: USD 1.0=" + currency + " " + rate);
            return rate;
        } catch (Exception e) {
View Full Code Here

        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse(procDefIS);

            XPath xpath = XPathFactory.newInstance().newXPath();

            NodeList nodeList = (NodeList) xpath.evaluate("//userTask | //serviceTask | //scriptTask", doc,
                    XPathConstants.NODESET);
            for (int i = 0; i < nodeList.getLength(); i++) {
                result.add(nodeList.item(i).getAttributes().getNamedItem("id").getNodeValue());
            }
        } catch (Exception e) {
View Full Code Here

      try
      {
         // System.setProperty("javax.xml.xpath.XPathFactory",
         // "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl") ;
         // XPathFactory xpfactory = XPathFactory.newInstance() ;
         XPath xpath = XPathFactory.newInstance().newXPath();
         XPathExpression clientTypeExp = xpath.compile("/clients-type/client-type");
         XPathExpression nameExp = xpath.compile("name/text()");
         XPathExpression userAgentPatternExp = xpath.compile("userAgentPattern/text()");
         XPathExpression preferredMimeTypeExp = xpath.compile("preferredMimeType/text()");
         XPathExpression rendererExp = xpath.compile("renderer/text()");
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         java.net.URL url = cl.getResource("conf/portal/clients-type.xml");
         // S ystem.setProperty("javax.xml.parsers.DocumentBuilderFactory",
         // "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl") ;
         // S ystem.out.println("==================> " +
View Full Code Here

      //
      ServletContext servletContext = getServletContext();

      // XPath expression for selecting the url pattern for this servlet instance
      String exprValue = "//servlet-mapping[servlet-name='" + servletName + "']/url-pattern";
      XPath xpath = XPathFactory.newInstance().newXPath();
      XPathExpression expr;
      try
      {
         expr = xpath.compile(exprValue);
      }
      catch (XPathExpressionException e)
      {
         throw new ServletException(e);
      }
View Full Code Here

    } else if (wicketId.startsWith("noteBackLink_")) {
      // Link back from a note to its (first) noteref.
      String idref = elt.getAttribute("idref");
      // Find candidate noterefs in this chapter
      XmlSection sec = getModel().getObject();
      XPath xPath = XPathFactory.newInstance().newXPath();
      xPath.setNamespaceContext(XmlService.get().getNamespaceContext());
      XmlSection linkSection = null;
      String linkText = "?";
      try {
        String path = String.format("//dtb:noteref[@idref='#%s']", idref);
        NodeList nl = (NodeList) xPath.evaluate(path, sec.getXmlDocument().getDocument().getDocumentElement(), XPathConstants.NODESET);
        if (nl.getLength() > 0) {
          Element node = null;
          node = (Element) nl.item(0);
          linkText = node.getTextContent();
          // Scan parents until you find the smallest enclosing XML Section.
View Full Code Here

    /**
     * Create the specified XPath expression with the namespaces added via
     * addNamespace().
     */
    public static XPath createXPath(Map<String, String> namespaces) throws Exception {
        XPath xpath = XPathFactory.newInstance().newXPath();

        if (namespaces != null) {
            xpath.setNamespaceContext(new MapNamespaceContext(namespaces));
        }

        return xpath;
    }
View Full Code Here

    @Test
    public void testXPathFactory() throws Exception {
        XPathFactory factory = XPathFactory.newInstance();
        Assert.assertNotNull("XPathFactory not null", factory);
        XPath xpath = factory.newXPath();
        URL resurl = getClass().getClassLoader().getResource("simple.xml");
        InputSource inputSource = new InputSource(resurl.openStream());
        String content = xpath.evaluate("/root/child", inputSource);
        Assert.assertEquals("content", content);
    }
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPath

Copyright © 2018 www.massapicom. 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.