Package javax.xml.xpath

Examples of javax.xml.xpath.XPathExpression


        String to = assignment.getTo();
       
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpathFrom = factory.newXPath();

        XPathExpression exprFrom = xpathFrom.compile(from);

        XPath xpathTo = factory.newXPath();

        XPathExpression exprTo = xpathTo.compile(to);

        Object target = null;
        Object source = null;
       
        if (isInput) {
            source = context.getVariable(sourceExpr);
            target = ((WorkItem) workItem).getParameter(targetExpr);
        } else {
            target = context.getVariable(targetExpr);
            source = ((WorkItem) workItem).getResult(sourceExpr);
        }
       
        Object targetElem = null;
       
//        XPATHExpressionModifier modifier = new XPATHExpressionModifier();
//        // modify the tree, returning the root node
//        target = modifier.insertMissingData(to, (org.w3c.dom.Node) target);

        // now pick the leaf for this operation
        if (target != null) {
            org.w3c.dom.Node parent = null;
                parent = ((org.w3c.dom.Node) target).getParentNode();
               
               
            targetElem = exprTo.evaluate(parent, XPathConstants.NODE);
           
            if (targetElem == null) {
                throw new RuntimeException("Nothing was selected by the to expression " + to + " on " + targetExpr);
            }
        }
View Full Code Here


        final XPath xpath = XPathFactory.newInstance().newXPath();
        NamespaceBinder resolver = new NamespaceBinder();
        resolver.declarePrefix(CATALONG_URI_PREFIX, CATALONG_URI);
        xpath.setNamespaceContext(resolver);
        final String count = "count(" + testPath + ")";
        XPathExpression expr = xpath.compile(count);
        final Document catalog = catalogPool.borrowObject();
        final Double d = (Double) expr.evaluate(catalog, XPathConstants.NUMBER);
        catalogPool.returnObject(catalog);
        return d.intValue();
    }
View Full Code Here

        final XPath xpath = XPathFactory.newInstance().newXPath();
        NamespaceBinder resolver = new NamespaceBinder();
        resolver.declarePrefix(XQTSTestBase.CATALONG_URI_PREFIX, XQTSTestBase.CATALONG_URI);
        xpath.setNamespaceContext(resolver);
        final String count = "count(" + testPath + ")";
        XPathExpression expr = xpath.compile(count);
        final Double d = (Double) expr.evaluate(catalog, XPathConstants.NUMBER);
        return d.intValue();
    }
View Full Code Here

    /**
     * Evaluates the expression as the given result type
     */
    protected String evaluateAs(String xml) {
        // pool a pre compiled expression from pool
        XPathExpression xpathExpression = pool.poll();
        if (xpathExpression == null) {
          logger.trace("Creating new XPathExpression as none was available from pool");
            // no avail in pool then create one
            try {
                xpathExpression = createXPathExpression();
View Full Code Here

  }

  protected XPathExpression getXPathExpression(String sExpression)
    throws XPathExpressionException
  {
    XPathExpression expression = xPathExpressions.get(sExpression);
    if (null == expression)
    {
      XPath xPath = xPathFactory.newXPath();
      expression = xPath.compile(sExpression);
      xPathExpressions.put(sExpression, expression);
View Full Code Here

  public List<Node> findAllNodes(Node parent, String nodeName)
    throws XPathExpressionException
  {
    NodeList nodes = null;
    final String sXPath = "//" + nodeName;
    XPathExpression xPathExpression = getXPathExpression(sXPath);
    nodes = (NodeList) xPathExpression.evaluate(parent, XPathConstants.NODESET);
    List<Node> realNodeList = createRealNodeList(nodes);
    return realNodeList;
  }
View Full Code Here

  public List<Node> getChildren(Node parent, String nodeName)
    throws XPathExpressionException
  {
    NodeList nodes = null;
    final String sXPath = nodeName;
    XPathExpression xPathExpression = getXPathExpression(sXPath);
    nodes = (NodeList) xPathExpression.evaluate(parent, XPathConstants.NODESET);
    List<Node> realNodeList = createRealNodeList(nodes);
    return realNodeList;
  }
View Full Code Here

                String s = r.getAttributeValue(null, "schemaLocation");
                if (StringUtils.isEmpty(s)) {
                    Document d = StaxUtils.read(r);
                    XPath p = XPathFactory.newInstance().newXPath();
                    p.setNamespaceContext(new W3CNamespaceContext(d.getDocumentElement()));
                    XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node"));
                    for (XmlSchema schema : schemas.getXmlSchemas()) {
                        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
                            continue;
                        }
                        Object src = getSchemaNode(schema, schemas);
                        NodeList nodes = (NodeList)xpe.evaluate(src, XPathConstants.NODESET);
                        if (nodes.getLength() > 0) {
                            String key = schema.getSourceURI();
                            binding = convertToTmpInputSource(d.getDocumentElement(), key);
                            opts.addBindFile(binding);
                            binding = null;
View Full Code Here

    }

    private static String xpathGetText(Document doc, String expression) throws XPathExpressionException {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        XPathExpression expr = xPath.compile(expression);

        return (String) expr.evaluate(doc, XPathConstants.STRING);
    }
View Full Code Here

     * @throws XPathExpressionException
     */
    private static List<String> xpathGetAttributeValueList(Document doc, String expression, String attribute) throws XPathExpressionException {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        XPathExpression expr = xPath.compile(expression);

        NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);

        List<String> attributeValues = new ArrayList<String>();

        for (int i = 0; i < nl.getLength(); i++) {
            attributeValues.add(((Element) nl.item(i)).getAttribute(attribute));
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPathExpression

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.