Click here to Skip to main content
15,885,278 members
Articles / Web Development / XHTML

A non-well-formed HTML Parser and CSS Resolver

Rate me:
Please Sign up or sign in to vote.
2.86/5 (14 votes)
20 Jul 20072 min read 109.1K   989   57  
A non-well-formed HTML parser and CSS Resolver builded by pure .NET C#
using System;
using System.Collections.Generic;

namespace DOL.DHtml.DCssResolver
{
    internal sealed class DCssSpecificity : IComparable<DCssSpecificity>
    {

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

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public DCssSpecificity()
        {
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        public DCssSpecificity(DCssSpecificity other)
        {
            m_a = other.m_a;
            m_b = other.m_b;
            m_c = other.m_c;
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        public DCssSpecificity(int a, int b, int c)
        {
            m_a = a;
            m_b = b;
            m_c = c;
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        public void Add(DCssSpecificity other)
        {
            m_a += other.m_a;
            m_b += other.m_b;
            m_c += other.m_c;
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public int A
        {
            get
            {
                return m_a;
            }
            set
            {
                m_a = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public int B
        {
            get
            {
                return m_b;
            }
            set
            {
                m_b = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        public int C
        {
            get
            {
                return m_c;
            }
            set
            {
                m_c = value;
            }
        }

        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(DCssSpecificity other)
        {
            if(m_a > other.m_a)
                return 1;
            else if(m_a < other.m_a)
                return -1;
            else if(m_b > other.m_b)
                return 1;
            else if(m_b < other.m_b)
                return -1;
            else if(m_c > other.m_c)
                return 1;
            else if(m_c < other.m_c)
                return -1;

            return 0;
        }

    #endregion

    /////////////////////////////////////////////////////////////////////////////////
    #region �������

        /// <summary>
        /// 
        /// </summary>
        private int m_a = 0; // count the number of ID attributes in the selector (= a) 
        /// <summary>
        /// 
        /// </summary>
        private int m_b = 0; // count the number of other attributes and pseudo-classes in the selector (= b) 
        /// <summary>
        /// 
        /// </summary>
        private int m_c = 0; // count the number of element names in the selector (= c) 

    #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


Written By
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.

Comments and Discussions