Package org.w3c.dom.traversal

Examples of org.w3c.dom.traversal.NodeIterator


            if(xpath != null)
            {
                Transformer serializer = TransformerFactory.newInstance().newTransformer();
                serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

                NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
                Node n;
                while ((n = nl.nextNode())!= null)
                {
                    SAXResult result = new SAXResult(this.contentHandler);
                    result.setLexicalHandler(this.lexicalHandler);
                    serializer.transform(new DOMSource(n), result);
                }
View Full Code Here


            CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
            XObject result = cachedXPathAPI.eval(doc, xpath);
            if (result.bool())
              return true;
            else {
              NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
              return (iterator.nextNode() != null);
            }

        } catch (Throwable e) {
            return false;
        }
View Full Code Here

          "Around ...<div id=\"div_super\" class=\"div_super\"..."));
    }
  }

  private List<Element> getScripts(final String type) {
    NodeIterator nodeIterator = ((DocumentTraversal) document)
    .createNodeIterator(document, NodeFilter.SHOW_ELEMENT,
        new NodeFilter() {
          public short acceptNode(Node n) {
            if ("script".equalsIgnoreCase(n.getNodeName()) &&
                type.equals(((Element) n).getAttribute("type"))) {
              return NodeFilter.FILTER_ACCEPT;
            }
            return NodeFilter.FILTER_REJECT;
          }
        }, false);
       
    List<Element> scripts = Lists.newArrayList();
    for (Node n = nodeIterator.nextNode(); n != null; n = nodeIterator.nextNode()) {
      scripts.add((Element) n);
    }
   
    return scripts;
  }
View Full Code Here

           String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {getTypeString(m_resultType)});                       
       throw new XPathException(XPathException.TYPE_ERR,fmsg); // Can not convert {0} to a single node. This getter applies to types
                                                                 // ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE.
      }
 
    NodeIterator result = null;
    try {
      result = m_resultObj.nodeset();
    } catch (TransformerException te) {
      throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
    }
       
        if (null == result) return null;
       
        Node node = result.nextNode();
        
        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
View Full Code Here

          Node contextNode, String str, Node namespaceNode)
            throws TransformerException
  {

    // Have the XObject return its result as a NodeSetDTM.
    NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

    // Return the first node, or null
    return nl.nextNode();
  }
View Full Code Here

          Node contextNode, String str, Node namespaceNode)
            throws TransformerException
  {

    // Have the XObject return its result as a NodeSetDTM.
    NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

    // Return the first node, or null
    return nl.nextNode();
  }
View Full Code Here

        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//        "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//         This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
      }
 
    NodeIterator result = null;
    try {
      result = m_resultObj.nodeset();
    } catch (TransformerException te) {
      throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
    }
       
        if (null == result) return null;
       
        Node node = result.nextNode();
        
        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
View Full Code Here

        if ( returnType.equals( XPathConstants.NODESET ) ) {
            return resultObject.nodelist();
        }
        // XPathConstants.NODE
        if ( returnType.equals( XPathConstants.NODE ) ) {
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            return ni.nextNode();
        }
        // If isSupported check is already done then the execution path
        // shouldn't come here. Being defensive
        String fmsg = XSLMessages.createXPATHMessage(
                XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
View Full Code Here

        if ( returnType.equals( XPathConstants.NODESET ) ) {
            return resultObject.nodelist();
        }
        // XPathConstants.NODE
        if ( returnType.equals( XPathConstants.NODE ) ) {
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            return ni.nextNode();
        }
        String fmsg = XSLMessages.createXPATHMessage(
                XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
                new Object[] { returnType.toString()});
        throw new IllegalArgumentException( fmsg );
View Full Code Here

        if ( returnType.equals( XPathConstants.NODESET ) ) {
            return resultObject.nodelist();
        }
        // XPathConstants.NODE
        if ( returnType.equals( XPathConstants.NODE ) ) {
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            return ni.nextNode();
        }
        // JSTLXPathConstants.OBJECT
        if ( returnType.equals( JSTLXPathConstants.OBJECT ) ) {
            if (resultObject instanceof com.sun.org.apache.xpath.internal.objects.XNodeSet)
                return resultObject.nodelist();
View Full Code Here

TOP

Related Classes of org.w3c.dom.traversal.NodeIterator

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.