0

I have never had the need to parse any text file to extract data so I don't know anything about it.

I have been assigned a task in which I have to allow user to load a Cascading Style Sheet file (.css) and parse it to extract and build a list of styles in three categories:

  1. HTML tag based styles
  2. HTML element based styles
  3. HTML class based styles

Then I have to allow user to edit a style (by Dbl Clicking on it) and update the style being edited as the same location in the .css file.

I searched the internet but could not find any VCL that will allow me to parse a .css file.

Please guide me as to how we can parse a .css file.

Olivier
  • 13,283
  • 1
  • 8
  • 24
Yogi Yang 007
  • 5,147
  • 10
  • 56
  • 77
  • [This link](https://stackoverflow.com/questions/3618381/parse-a-css-file-with-php) could help you. It shows how to parse CSS with PHP code. Please note that StackOverflow is not a free code writing or translation service. We're more than happy to help once you've made an effort to solve the problem yourself and run into difficulties. When that happens, you can explain the problem you're having, include the relevant portions of your code (and any original code). – fpiette Jul 05 '21 at 06:15
  • 1
    If you just want to extract the rules, looking for `{` and `}` is the key. – Olivier Jul 05 '21 at 07:17
  • "_HTML tag_" and "_HTML class_" do not exist - you might mean the CSS selectors for attributes in general or the `id=` attribute, and the `class=` attribute. An HTML element consists of either one or two tags - it makes no sense for CSS to distinguish between those. See [CSS selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors). – AmigoJack Jul 05 '21 at 08:54
  • 1
    @AmigoJack The OP means rules like `tag {...}`, `#id {...}` and `.class {...}`. – Olivier Jul 05 '21 at 09:00
  • @Olivier Tags are `
    ` **and** `
    `, while `div` (unbound to its tags) is an element. Synonymizing the terms will only increase ambiguity. There's a difference between missing a tag and missing a whole element.
    – AmigoJack Jul 05 '21 at 09:52

0 Answers0