Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

A non-well-formed HTML Parser and CSS Resolver

, 20 Jul 2007
A non-well-formed HTML parser and CSS Resolver builded by pure .NET C#
dols_html.zip
DOLS
Backup
DFuzzy.rar
DOLRss.rar
DXHtmlObjectModel.rar
bin
Debug
doc
Check.doc
DOL
DBase
DHtml
DCssResolver
DHtmlParser
Node
DOLBase.csproj.user
DOLHtml.csproj.user
DOLS.suo
HTMLTreeDemo
bin
Debug
HTMLTreeDemo.vshost.exe
Google News.files
cleardot.gif
envelope.gif
news(1).jpg
news(10).jpg
news(11).jpg
news(12).jpg
news(13).jpg
news(14).jpg
news(15).jpg
news(16).jpg
news(17).jpg
news(18).jpg
news(19).jpg
news(2).jpg
news(20).jpg
news(21).jpg
news(22).jpg
news(23).jpg
news(24).jpg
news(25).jpg
news(3).jpg
news(4).jpg
news(5).jpg
news(6).jpg
news(7).jpg
news(8).jpg
news(9).jpg
news.gif
news.jpg
Thumbs.db
obj
Debug
TempPE
Properties
Settings.settings
VTune
HTMLTreeDemo.vpj
obj
Debug
TempPE
Properties
Settings.settings
VTune
DOLBase.vpj
DOLHtml.vpj
DOLHtml.vws
dols_html_20070322.zip
DFuzzy.rar
DOLRss.rar
DXHtmlObjectModel.rar
Demo
bin
Debug
Google News.files
cleardot.gif
envelope.gif
news(1).jpg
news(10).jpg
news(11).jpg
news(12).jpg
news(13).jpg
news(14).jpg
news(15).jpg
news(16).jpg
news(17).jpg
news(18).jpg
news(19).jpg
news(2).jpg
news(20).jpg
news(21).jpg
news(22).jpg
news(23).jpg
news(24).jpg
news(25).jpg
news(3).jpg
news(4).jpg
news(5).jpg
news(6).jpg
news(7).jpg
news(8).jpg
news(9).jpg
news.gif
news.jpg
obj
Properties
Check.doc
DOLBase.csproj.user
DOLS.suo
DOLS.vsmdi
Settings.settings
/*****************************************************************************\
>	Copyright 2004 DOL for design studio.
>
>	DOLS DHtmlNode Class
>
>	E-mail�G	  nomad_libra.tw@yahoo.com.tw
>	E-mail�G	  jameshrsp@ms2.url.com.tw
>
\*****************************************************************************/

// DHtmlNode.cs: implementation of the DHtmlNode class.
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Text;

namespace DOL.DHtml.DHtmlParser.Node
{
	/// <summary>
	/// The DHtmlNode is the base for all objects that may appear in HTML.
	/// </summary>
    public abstract class DHtmlNode : DOL.DBase.DIDiagnosisable, ICloneable
	{

	/////////////////////////////////////////////////////////////////////////////////
	#region �򥻾ާ@	

		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This constructor is used by the subclasses.
		/// </summary>
		protected DHtmlNode()
		{
		}

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This constructor is used by the subclasses.
        /// </summary>
        protected DHtmlNode(DHtmlNode obj)
        {
            System.Diagnostics.Debug.Assert(obj != null);

            obj.AssertValid();

            m_parent = obj.m_parent;
            m_nodeID = obj.m_nodeID;
            m_bindObject = obj.m_bindObject;
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public abstract object Clone();

		/////////////////////////////////////////////////////////////////////////////        
		/// <summary>
		/// �O�_�����Ī���
		/// </summary>
		public abstract void AssertValid();

		/////////////////////////////////////////////////////////////////////////////       
		/// <summary>
		/// �ɦL����
		/// </summary>
		/// <param name="buffer"> �ɦL���w�İ� </param>
		/// <param name="prefix"> �Y�Ƥ�r </param>
		public abstract void Dump(StringBuilder buffer, string prefix);

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This is the text associated with this node.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.HTML;
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return m_nodeID;
        }

    #endregion

    /////////////////////////////////////////////////////////////////////////////////
    #region �ץX

		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This will return the full HTML to represent this node (and all child nodes).
		/// </summary>
        public string HTML 
        {
            get
            {
                StringBuilder stringBuilder = new StringBuilder();
                TransformHTML(stringBuilder, 0);

                return stringBuilder.ToString();
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This will return the full HTML to represent this node (and all child nodes)
        /// </summary>
        internal abstract void TransformHTML(StringBuilder writer, int indentDepth);

    #endregion

    /////////////////////////////////////////////////////////////////////////////////
    #region �����ާ@

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public int NodeID
        {
            get
            {
                return m_nodeID;
            }
            set
            {
                m_nodeID = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public abstract string NodeName
        {
            get;
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public Object BindObject
        {
            get
            {
                return m_bindObject;
            }
            set
            {
                m_bindObject = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This will return the parent of this node, or null if there is none.
        /// </summary>
        public DHtmlElement Parent
        {
            get
            {
                return m_parent;
            }
            internal set
            {
                m_parent = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This will return the previous sibling of this node, or null if there is none.
        /// </summary>
        public DHtmlNode PreviousSibling
        {
            get
            {
                DHtmlNode previousSibling = null;
                if(m_parent != null)
                {
                    int index = m_parent.Nodes.IndexOf(this);
                    System.Diagnostics.Debug.Assert(index != -1);                    
                    if(index - 1 >= 0)
                        previousSibling = m_parent.Nodes[index - 1];
                }

                return previousSibling;
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// This will return the next sibling of this node, or null if there is none.
        /// </summary>
        public DHtmlNode NextSibling
        {
            get
            {
                DHtmlNode nextSibling = null;
                if(m_parent != null)
                {
                    int index = m_parent.Nodes.IndexOf(this);
                    System.Diagnostics.Debug.Assert(index != -1); 
                    if(index + 1 < m_parent.Nodes.Count)
                        nextSibling = m_parent.Nodes[index + 1];
                }

                return nextSibling;
            }
        }

		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This will return true if this is a root node (has no parent).
		/// </summary>
		public bool IsRoot
		{
			get
			{
				return m_parent == null;
			}
		}

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public abstract bool IsLeaf { get; }
       
		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This will return true if the node passed is a descendent of this node.
		/// </summary>
		/// <param name="node">The node that might be the parent or grandparent (etc.)</param>
		/// <returns>True if this node is a descendent of the one passed in.</returns>
		public bool IsDescendentOf(DHtmlNode node)
		{
            System.Diagnostics.Debug.Assert(node != null);

            bool reault = false;

			DHtmlNode parent = m_parent;
			while(parent != null)
			{
                if (parent == node)
                {
                    reault = true;
                    break;
                }

				parent = parent.m_parent;
			}

            return reault;
		}

		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This will return true if the node passed is one of the children or grandchildren of this node.
		/// </summary>
		/// <param name="node">The node that might be a child.</param>
		/// <returns>True if this node is an ancestor of the one specified.</returns>
		public bool IsAncestorOf(DHtmlNode node)
		{
            System.Diagnostics.Debug.Assert(node != null);
			return node.IsDescendentOf(this);
		}

		/////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// This will return the ancstor that is common to this node and the one specified.
		/// </summary>
		/// <param name="node">The possible node that is relative</param>
		/// <returns>The common ancestor, or null if there is none</returns>
		public DHtmlNode GetCommonAncestor(DHtmlNode node)
		{
            System.Diagnostics.Debug.Assert(node != null);

            DHtmlNode commonAncestor = null;

			DHtmlNode thisParent = this;
            while(commonAncestor != null && thisParent != null)
			{
				DHtmlNode thatParent = node;
                while(commonAncestor != null && thatParent != null)
				{
                    if(thisParent == thatParent)
                      commonAncestor = thisParent;
                   
					thatParent = thatParent.Parent;
				}
				thisParent = thisParent.Parent;
			}

            return commonAncestor;
		}

    #endregion

    /////////////////////////////////////////////////////////////////////////////////
    #region �������
		
		/// <summary>
		/// 
		/// </summary>
        protected DHtmlElement m_parent = null;
        /// <summary>
        /// 
        /// </summary>
        protected int m_nodeID = 0;
        /// <summary>
        /// 
        /// </summary>
        protected Object m_bindObject = null;

    #endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

James S.F. Hsieh
Web Developer
United States United States
James S.F. Hsieh(Nomad Libra) Working as engineer for "Corel Intervideo" company situated in Taiwan.
He received his master degree in Graduate Institute of Network Learning Technology, National Central University, Taiwan in 2006.
His research interests are semantic Web services, intelligent software agent, machine learning, algorithm, software
engineering and multimedia programming.

| Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 20 Jul 2007
Article Copyright 2007 by James S.F. Hsieh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid