Click here to Skip to main content
15,885,757 members
Articles / Web Development / CSS3

AngleSharp

Rate me:
Please Sign up or sign in to vote.
5.00/5 (87 votes)
3 Jul 2013BSD28 min read 261.6K   4.3K   166  
Bringing the DOM to C# with a HTML5/CSS3 parser written in C#.
using System;
using System.Diagnostics;

namespace AngleSharp.Xml
{
    /// <summary>
    /// The abstract base class of any XML token.
    /// </summary>
    [DebuggerStepThrough]
    abstract class XmlToken
    {
        #region Members

        static XmlEndOfFileToken eof;
        protected XmlTokenType _type;

        #endregion

        #region Factory

        /// <summary>
        /// Gets the end of file token.
        /// </summary>
        public static XmlEndOfFileToken EOF
        {
            get { return eof ?? (eof = new XmlEndOfFileToken()); }
        }

        /// <summary>
        /// Creates a new comment token.
        /// </summary>
        /// <param name="data">The data in the comment.</param>
        /// <returns>The created token.</returns>
        public static XmlToken Comment(String data)
        {
            return new XmlCommentToken(data);
        }

        /// <summary>
        /// Creates a new doctype token.
        /// </summary>
        /// <returns>The created token.</returns>
        public static XmlDoctypeToken Doctype()
        {
            return new XmlDoctypeToken();
        }

        /// <summary>
        /// Creates a new declaration token.
        /// </summary>
        /// <returns>The created token.</returns>
        public static XmlDeclarationToken Declaration()
        {
            return new XmlDeclarationToken();
        }

        /// <summary>
        /// Creates a new character token.
        /// </summary>
        /// <param name="character">The character data.</param>
        /// <returns>The created token.</returns>
        public static XmlCharacterToken Character(Char character)
        {
            return new XmlCharacterToken(character);
        }

        /// <summary>
        /// Creates a new open tag token.
        /// </summary>
        /// <returns>The created token.</returns>
        public static XmlTagToken OpenTag()
        {
            return new XmlTagToken { _type = XmlTokenType.StartTag };
        }

        /// <summary>
        /// Creates a new close tag token.
        /// </summary>
        /// <returns>The created token.</returns>
        public static XmlTagToken CloseTag()
        {
            return new XmlTagToken { _type = XmlTokenType.EndTag };
        }

        /// <summary>
        /// Creates a new processing instruction token.
        /// </summary>
        /// <returns>The created token.</returns>
        public static XmlPIToken Processing()
        {
            return new XmlPIToken();
        }

        /// <summary>
        /// Creates a new CData token.
        /// </summary>
        /// <param name="data">The raw data.</param>
        /// <returns>The created token.</returns>
        public static XmlCDataToken CData(String data)
        {
            return new XmlCDataToken(data);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the type of the token.
        /// </summary>
        public XmlTokenType Type
        {
            get { return _type; }
        }

        /// <summary>
        /// Gets if the token is a character token and contains a
        /// white-space character.
        /// </summary>
        public virtual Boolean IsIgnorable
        {
            get { return false; }
        }

        #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, along with any associated source code and files, is licensed under The BSD License


Written By
Chief Technology Officer
Germany Germany
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.

During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.

Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.

Comments and Discussions