Click here to Skip to main content
15,893,266 members
Articles / Web Development / CSS

A Simple CSS Parser

Rate me:
Please Sign up or sign in to vote.
4.79/5 (9 votes)
25 Feb 2012CPOL2 min read 62.1K   3.2K   26  
A simple CSS parser designed to work with iTextSharp for HTML to PDF generation
using System;
using System.Collections.Generic;
namespace CValenzuela.Common
{
    /// <summary>
    /// Object used to parse CSS Files.
    /// This can also be used to minify a CSS file though I
    /// doubt this will pass all the same tests as YUI compressor
    /// or some other tool
    /// </summary>
    public interface ICSSParser : IEnumerable<KeyValuePair<String, List<KeyValuePair<String, String>>>>
    {
        /// <summary>
        /// Original Style Sheet loaded
        /// </summary>
        String StyleSheet { get; set; }
        
        /// <summary>
        /// Gets all styles in an Immutable collection
        /// </summary>
        IEnumerable<KeyValuePair<String, List<KeyValuePair<String, String>>>> Styles { get; }       

        /// <summary>
        /// Gets the CSS classes.
        /// </summary>
        Dictionary<String, Dictionary<String, String>> Classes { get; }
     
        /// <summary>
        /// Gets the elements.
        /// </summary>
        Dictionary<String, Dictionary<String, String>> Elements { get; }

        /// <summary>
        /// Removes all elements from the <see cref="CSSParser"></see>.
        /// </summary>
        new void Clear();

        /// <summary>
        /// Reads the specified cascading style sheet.
        /// </summary>
        /// <param name="CascadingStyleSheet">The cascading style sheet.</param>
        void Read(String CascadingStyleSheet);

        /// <summary>
        /// Reads the CSS file.
        /// </summary>
        /// <param name="Path">The path.</param>
        void ReadCSSFile(String Path);        
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I am a full stack software engineer and architect with the majority of my experience on the Microsoft Stack. I teach martial arts for a non-profit organization.

Comments and Discussions