Package org.apache.xpath

Examples of org.apache.xpath.NodeSet


   * in ni2
   */ 
  public static NodeSet intersection(NodeIterator ni1, NodeIterator ni2)
      throws javax.xml.transform.TransformerException
  {
    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);
    NodeSet inter= new NodeSet();
    inter.setShouldCacheNodes(true);
    for (int i=0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);
      if(ns2.contains(n))
        inter.addElement(n);
    }
    return inter;
  }
View Full Code Here


   * in ni2
   */ 
  public static NodeSet difference(NodeIterator ni1, NodeIterator ni2)
      throws javax.xml.transform.TransformerException 
  {
    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);
    // NodeSet inter= new NodeSet();
    NodeSet diff = new NodeSet();
    diff.setShouldCacheNodes(true);   
    for (int i = 0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);
      if(!ns2.contains(n))
        diff.addElement(n);
    }
    return diff;
  }
View Full Code Here

   * only include the first such node found.
   */ 
  public static NodeSet distinct(NodeIterator ni)
      throws javax.xml.transform.TransformerException 
  {
    NodeSet ns = new NodeSet(ni);
    NodeSet dist = new NodeSet();
    dist.setShouldCacheNodes(true);   
    Hashtable stringTable = new Hashtable();
    for (int i = 0; i < ns.getLength(); i++)
    {
      Node n = ns.elementAt(i);
      String key = DOMHelper.getNodeData(n);
      if (!stringTable.containsKey(key))
      {
        stringTable.put(key, n);
        dist.addElement(n);
      }
    }
    return dist;
  }
View Full Code Here

   * @param ni2 NodeIterator for second node-set
   * @return true if ni1 and ni2 contain exactly the same set of nodes.
   */ 
  public static boolean hasSameNodes(NodeIterator ni1, NodeIterator ni2)
  {
    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);   
    if (ns1.getLength() != ns2.getLength())
      return false;
    for (int i = 0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);
      if(!ns2.contains(n))
        return false;
    }
    return true;
 
View Full Code Here

   */ 
  public static NodeSet tokenize(ExpressionContext myContext, String toTokenize, String delims)
  {
    Document lDoc = myContext.getContextNode().getOwnerDocument();
    StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
    NodeSet resultSet = new NodeSet();
    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(lDoc.createTextNode(lTokenizer.nextToken()));
    }
    return resultSet;
View Full Code Here

    String textNodeValue;

    if (rtf instanceof NodeIterator)
    {
      return new NodeSet((NodeIterator) rtf);
    }
    else
    {
      if (rtf instanceof String)
      {
        textNodeValue = (String) rtf;
      }
      else if (rtf instanceof Boolean)
      {
        textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
      }
      else if (rtf instanceof Double)
      {
        textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
      }
      else
      {
        textNodeValue = rtf.toString();
      }

      // This no longer will work right since the DTM.
      // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
      try
      {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document myDoc = db.newDocument();
       
        Text textNode = myDoc.createTextNode(textNodeValue);
        DocumentFragment docFrag = myDoc.createDocumentFragment();
 
        docFrag.appendChild(textNode);
 
        return new NodeSet(docFrag);
      }
      catch(ParserConfigurationException pce)
      {
        throw new org.apache.xml.utils.WrappedRuntimeException(pce);
      }
View Full Code Here

   */
  public static NodeSet intersection(NodeIterator ni1, NodeIterator ni2)
          throws javax.xml.transform.TransformerException
  {

    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);
    NodeSet inter = new NodeSet();

    inter.setShouldCacheNodes(true);

    for (int i = 0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);

      if (ns2.contains(n))
        inter.addElement(n);
    }

    return inter;
  }
View Full Code Here

   */
  public static NodeSet difference(NodeIterator ni1, NodeIterator ni2)
          throws javax.xml.transform.TransformerException
  {

    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);

    // NodeSet inter= new NodeSet();
    NodeSet diff = new NodeSet();

    diff.setShouldCacheNodes(true);

    for (int i = 0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);

      if (!ns2.contains(n))
        diff.addElement(n);
    }

    return diff;
  }
View Full Code Here

  {

    // Set up our resulting NodeSet and the hashtable we use to keep track of duplicate
    // strings.

    NodeSet dist = new NodeSet();
    dist.setShouldCacheNodes(true);

    Hashtable stringTable = new Hashtable();

    Node currNode = ni.nextNode();

    while (currNode != null)
    {
      String key = myContext.toString(currNode);

      if (!stringTable.containsKey(key))
      {
        stringTable.put(key, currNode);
        dist.addElement(currNode);
      }
      currNode = ni.nextNode();
    }

    return dist;
View Full Code Here

   * @return true if ni1 and ni2 contain exactly the same set of nodes.
   */
  public static boolean hasSameNodes(NodeIterator ni1, NodeIterator ni2)
  {

    NodeSet ns1 = new NodeSet(ni1);
    NodeSet ns2 = new NodeSet(ni2);

    if (ns1.getLength() != ns2.getLength())
      return false;

    for (int i = 0; i < ns1.getLength(); i++)
    {
      Node n = ns1.elementAt(i);

      if (!ns2.contains(n))
        return false;
    }

    return true;
  }
View Full Code Here

TOP

Related Classes of org.apache.xpath.NodeSet

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.