/// <summary> Remove nodes not matching the given filter.</summary>
        /// <param name="filter">The filter to use.
        /// </param>
        /// <param name="recursive">If <code>true<code> digs into the children recursively.
        /// </param>
        public virtual void KeepAllNodesThatMatch(NodeFilter filter, bool recursive)
        {
            INode    node;
            NodeList children;

            for (int i = 0; i < m_iSize;)
            {
                node = nodeData[i];
                if (!filter.Accept(node))
                {
                    Remove(i);
                }
                else
                {
                    if (recursive)
                    {
                        children = node.Children;
                        if (null != children)
                        {
                            children.KeepAllNodesThatMatch(filter, recursive);
                        }
                    }
                    i++;
                }
            }
        }
        /// <summary> Filter the list with the given filter.</summary>
        /// <param name="filter">The filter to use.
        /// </param>
        /// <param name="recursive">If <code>true<code> digs into the children recursively.
        /// </param>
        /// <returns> A new node array containing the nodes accepted by the filter.
        /// This is a linear list and preserves the nested structure of the returned
        /// nodes only.
        /// </returns>
        public virtual NodeList ExtractAllNodesThatMatch(NodeFilter filter, bool recursive)
        {
            INode    node;
            NodeList children;
            NodeList ret;

            ret = new NodeList();
            for (int i = 0; i < m_iSize; i++)
            {
                node = nodeData[i];
                if (filter.Accept(node))
                {
                    ret.Add(node);
                }
                if (recursive)
                {
                    children = node.Children;
                    if (null != children)
                    {
                        ret.Add(children.ExtractAllNodesThatMatch(filter, recursive));
                    }
                }
            }

            return(ret);
        }
Example #3
0
 /// <summary> Collect this node and its child nodes (if-applicable) into the collectionList parameter, provided the node
 /// satisfies the filtering criteria.<P>
 ///
 /// This mechanism allows powerful filtering code to be written very easily,
 /// without bothering about collection of embedded tags separately.
 /// e.g. when we try to get all the links on a page, it is not possible to
 /// get it at the top-level, as many tags (like form tags), can contain
 /// links embedded in them. We could get the links out by checking if the
 /// current node is a <see cref="CompositeTag"></see>, and going through its children.
 /// So this method provides a convenient way to do this.<P>
 ///
 /// Using collectInto(), programs get a lot shorter. Now, the code to
 /// extract all links from a page would look like:
 /// <pre>
 /// NodeList collectionList = new NodeList();
 /// NodeFilter filter = new TagNameFilter ("A");
 /// for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
 /// e.nextNode().collectInto(collectionList, filter);
 /// </pre>
 /// Thus, collectionList will hold all the link nodes, irrespective of how
 /// deep the links are embedded.<P>
 ///
 /// Another way to accomplish the same objective is:
 /// <pre>
 /// NodeList collectionList = new NodeList();
 /// NodeFilter filter = new TagClassFilter (LinkTag.class);
 /// for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
 /// e.nextNode().collectInto(collectionList, filter);
 /// </pre>
 /// This is slightly less specific because the LinkTag class may be
 /// registered for more than one node name, e.g. &lt;LINK&gt; tags too.
 /// </summary>
 /// <param name="list">The node list to collect acceptable nodes into.
 /// </param>
 /// <param name="filter">The filter to determine which nodes are retained.
 /// </param>
 public virtual void CollectInto(NodeList list, NodeFilter filter)
 {
     if (filter.Accept(this))
     {
         list.Add(this);
     }
 }
Example #4
0
		/// <summary> Remove nodes not matching the given filter.</summary>
		/// <param name="filter">The filter to use.
		/// </param>
		/// <param name="recursive">If <code>true<code> digs into the children recursively.
		/// </param>
		public virtual void KeepAllNodesThatMatch(NodeFilter filter, bool recursive)
		{
			INode node;
			NodeList children;
			
			for (int i = 0; i < m_iSize; )
			{
				node = nodeData[i];
				if (!filter.Accept(node))
					Remove(i);
				else
				{
					if (recursive)
					{
						children = node.Children;
						if (null != children)
							children.KeepAllNodesThatMatch(filter, recursive);
					}
					i++;
				}
			}
		}
Example #5
0
		/// <summary> Filter the list with the given filter.</summary>
		/// <param name="filter">The filter to use.
		/// </param>
		/// <param name="recursive">If <code>true<code> digs into the children recursively.
		/// </param>
		/// <returns> A new node array containing the nodes accepted by the filter.
		/// This is a linear list and preserves the nested structure of the returned
		/// nodes only.
		/// </returns>
		public virtual NodeList ExtractAllNodesThatMatch(NodeFilter filter, bool recursive)
		{
			INode node;
			NodeList children;
			NodeList ret;
			
			ret = new NodeList();
			for (int i = 0; i < m_iSize; i++)
			{
				node = nodeData[i];
				if (filter.Accept(node))
					ret.Add(node);
				if (recursive)
				{
					children = node.Children;
					if (null != children)
						ret.Add(children.ExtractAllNodesThatMatch(filter, recursive));
				}
			}
			
			return (ret);
		}
 /// <summary> Accept nodes that are not acceptable to the predicate filter.</summary>
 /// <param name="node">The node to check.
 /// </param>
 /// <returns> <code>true</code> if the node is not acceptable to the
 /// predicate filter, <code>false</code> otherwise.
 /// </returns>
 public virtual bool Accept(INode node)
 {
     return((null != mPredicate) && !mPredicate.Accept(node));
 }
Example #7
0
		/// <summary> Collect this node and its child nodes (if-applicable) into the collectionList parameter, provided the node
		/// satisfies the filtering criteria.<P>
		/// 
		/// This mechanism allows powerful filtering code to be written very easily,
		/// without bothering about collection of embedded tags separately.
		/// e.g. when we try to get all the links on a page, it is not possible to
		/// get it at the top-level, as many tags (like form tags), can contain
		/// links embedded in them. We could get the links out by checking if the
		/// current node is a <see cref="CompositeTag"></see>, and going through its children.
		/// So this method provides a convenient way to do this.<P>
		/// 
		/// Using collectInto(), programs get a lot shorter. Now, the code to
		/// extract all links from a page would look like:
		/// <pre>
		/// NodeList collectionList = new NodeList();
		/// NodeFilter filter = new TagNameFilter ("A");
		/// for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
		/// e.nextNode().collectInto(collectionList, filter);
		/// </pre>
		/// Thus, collectionList will hold all the link nodes, irrespective of how
		/// deep the links are embedded.<P>
		/// 
		/// Another way to accomplish the same objective is:
		/// <pre>
		/// NodeList collectionList = new NodeList();
		/// NodeFilter filter = new TagClassFilter (LinkTag.class);
		/// for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
		/// e.nextNode().collectInto(collectionList, filter);
		/// </pre>
		/// This is slightly less specific because the LinkTag class may be
		/// registered for more than one node name, e.g. &lt;LINK&gt; tags too.
		/// </summary>
		/// <param name="list">The node list to collect acceptable nodes into.
		/// </param>
		/// <param name="filter">The filter to determine which nodes are retained.
		/// </param>
		public virtual void CollectInto(NodeList list, NodeFilter filter)
		{
			if (filter.Accept(this))
			{
				list.Add(this);
			}
		}