473,811 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSS Parser Wanted

I need a way to extract css class names from a css file. Therefore I’m
looking for a CSS Parser, preferably freeware and written in C#.

Anybody know of such one?

Feb 5 '06 #1
7 5591
use a regular expression

http://www.kinlan.co.uk/2006/02/rege...om-css-20.html

--
Regards

John Timney
Microsoft MVP

"Rasmus" <Ra****@newsgro up.nospam> wrote in message
news:AC******** *************** ***********@mic rosoft.com...
I need a way to extract css class names from a css file. Therefore I'm
looking for a CSS Parser, preferably freeware and written in C#.

Anybody know of such one?

Feb 5 '06 #2
Thanks for the quick reply.

I'm not too good at using regex in c#. Could you provide a snippet of sample
code?

Feb 5 '06 #3
from google

http://www.c-sharpcorner.com/3/RegExpPSD.asp

--
Regards

John Timney
Microsoft MVP

"Rasmus" <Ra****@newsgro up.nospam> wrote in message
news:B3******** *************** ***********@mic rosoft.com...
Thanks for the quick reply.

I'm not too good at using regex in c#. Could you provide a snippet of
sample
code?

Feb 5 '06 #4
Can't seem to get it to work...

static void Main(string[] args){
string css = @"
..class1{
color:pink;
}

..class2{
color:blue;
}";

string patt =
@"\.[-]?[_a-zA-Z][_a-zA-Z0-9-]*|[^\0-\177]*\\[0-9a-f]{1,6}(\r\n[
\n\r\t\f])?|\\[^\n\r\f0-9a-f]*";
string[] arr = Regex.Split(css , patt);
}
Feb 5 '06 #5
According to the author the code should be as show below
http://www.kinlan.co.uk/2006/02/upda...-question.html
--
Regards

John Timney
Microsoft MVP
The code should have been:

string css = @"
..class1{
color:pink;
}
..class2{
color:blue;
}";
string patt =
@"\.[-]?[_a-zA-Z][_a-zA-Z0-9-]*|[^\0-\177]*\\[0-9a-f]{1,6}(\r\n[
\n\r\t\f])?|\\[^\n\r\f0-9a-f]*";
MatchCollection arr = Regex.Matches(c ss, patt);
}


"Rasmus" <Ra****@newsgro up.nospam> wrote in message
news:30******** *************** ***********@mic rosoft.com...
Can't seem to get it to work...

static void Main(string[] args){
string css = @"
.class1{
color:pink;
}

.class2{
color:blue;
}";

string patt =
@"\.[-]?[_a-zA-Z][_a-zA-Z0-9-]*|[^\0-\177]*\\[0-9a-f]{1,6}(\r\n[
\n\r\t\f])?|\\[^\n\r\f0-9a-f]*";
string[] arr = Regex.Split(css , patt);
}

Feb 6 '06 #6
Kinlan
2 New Member
Yeah, I made some simple mistakes in the original example but it is sorted.

if you want all the Matches then you need to use Regex.Matches.

I haven't done too much work on it since, but I will be trying to make more Regex's for parsing CSS.

www.kinlan.co.u k
Feb 16 '06 #7
Kinlan
2 New Member
I have update the regex.

http://www.kinlan.co.uk/2006/02/c-cs...ame-regex.html
Feb 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2374
by: Franz Steinhaeusler | last post by:
Hello NG, has anyone written such a thing in python? Where could I look for? (I need it for an editor written in wxPython to display function names, include, global variables, classes, ... in a sidepanel). kind regards, --
1
2706
by: Helge Ruistuen | last post by:
Hello, I'm using SAX parser to read a string of numbers defined as XML list type. Occasionally the 'characters' method is called twice, which means I need a buffer to read the entire string. My problem is that whenever "the split" (or second reading) occurs at a white space, I need to manually add a white space (avoid two number becoming one), while for the case that the parser start a second reading within a number, adding a white space...
3
2153
by: christopher diggins | last post by:
There seems to be a gazillion regular expression libraries. Most of them only work on text, but I wanted something that also worked on arbitrary sequences of data ( this is useful, for instance, in building parse trees from token lists ). This is possible, I think, using the Spirit library from Boost, but the syntax and complexity again is too much for me. I almost finished the YARD ( yet another recursive descent ) parser which is a really...
3
1968
by: cr88192 | last post by:
for various reasons, I added an imo ugly hack to my xml parser. basically, I wanted the ability to have binary payload within the xml parse trees. this was partly because I came up with a binary xml format (mentioned more later), and thought it would be "useful" to be able to store binary data inline with this format, and still wanted to keep things balanced (whatever the binary version can do, the textual version can do as well). the...
4
11449
by: Greg B | last post by:
Well since getopt() doesn't seem to be compatible with Windows, and the free implementation of it for Windows that I found still had some annoying restrictions, I thought I'd whip up a simple parser myself. Just wanted to see if anyone could provide me with some constructive criticism :) any feedback would be greatly appreciated ----------------------------------------------------------------------------- #include "stdio.h" #include...
5
1425
by: jatin.libra | last post by:
helloo iam working on a parser wherein i search for a few strings in thousands of lines... ie i have an open fifo from which i keep receiving lines and lines of data and iam supposed to search for a few strings(around 50 strings) in every line. just wanted to take ur opinion which sorting technique should i use... or if u guys have any examples that would be an extra help...
5
1876
by: Tino Lange | last post by:
Hi! I'm trying to use the csv Parser included with Python. Field Delimiter is "|", Line Delimiter is "#". Unfortunately it doesn't work as expected. The parser seems to just ignore the 'lineterminator'? Here's some example: > $ cat test.py > #! /usr/bin/env python
63
4814
by: Jake Barnes | last post by:
In the course of my research I stumbled upon this article by Alex Russel and Tim Scarfe: http://www.developer-x.com/content/innerhtml/default.html The case is made that innerHTML should never be used. I'm wondering, If I wanted all the content of BODY as a string, how else could I get except through innerHTML?
1
1847
by: Aaron Gray | last post by:
I am looking for an HTML parser that will parser malformed HTML Netscape bookmarks.html files. Ideally it will work with callbacks. Many thanks in advance, Aaron
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.