The XHTML WYSIWYG Editor For Desktop & Web Applications

CSS Parser Component

Overview

The CSS (Cascading Style Sheet) parser takes a CSS document, converts it to an XML document and back again. Since editing XML is easier than editing CSS, this is useful when you want to programmatically edit a CSS document or build your own CSS editor. This component can be used in environments that support COM such as Active Server Pages, Windows Scripting Host, Visual Basic, etc.

License
Freeware
Type
ActiveX DLL for 32 bit OS
Version
2.0
File Name
XCSSParser.dll
Download Package
x-css-parser.zip

Download

Download CSS Parser Component

Installation Instructions

  1. If not already installed, download and install MSXML 4 parser
  2. Move the dll to a directory like: C:\Program Files\XStandard\Bin\.
  3. Open a command prompt and cd to the directory where the dll is located.
  4. Type regsvr32 XCSSParser.dll
  5. Grant "Read & Execute" file permissions on this dll to Everyone.

Note, on Microsoft Vista, the command prompt must be "Run as administrator" as shown in the screen shot below.

Context menu for the command prompt showing the option to run as administrator.

Uninstall Instructions

  1. Open a command prompt and cd to the directory where the dll is located.
  2. Type regsvr32 -u XCSSParser.dll

API Reference: ProgID: XStandard.CSS2XML

Property ErrorCode As Long

(read-only)
Returns an error code if the parser failed to convert CSS to XML.

Property ErrorMessage As String

(read-only)
Returns an error message if the parser failed to convert CSS to XML.

Property Indent As Boolean

Indents the XML document for easy reading.

Sub Load(sPath As String)

Load CSS from a file.

Sub LoadCSS(sCSS As String)

Load CSS from a string.

Sub SaveAs(sPath As String, [bUnicode As Boolean = False])

Save XML to file.

Property XML As String

(read-only)
CSS data converted to XML.

API Reference: ProgID: XStandard.XML2CSS

Property CSS As String

(read-only)
XML data converted to CSS

Property ErrorCode As Long

(read-only)
Returns an error code if the parser failed to convert XML to CSS.

Property ErrorMessage As String

(read-only)
Returns an error message if the parser failed to convert XML to CSS.

Sub Load(sPath As String)

Load XML from file.

Sub LoadXML(sXML As String)

Load XML from string.

Sub SaveAs(sPath As String, [bUnicode As Boolean = False])

Save CSS to a file.

Examples

The examples below are for Active Server Pages. For Windows Scripting Host or Visual Basic, replace Server.CreateObject with CreateObject and replace Resonse.Write with MsgBox.

How to change the foreground color of an <h1> tag

  1. <%
  2. Dim objCSS, objXML, objDoc, objNode
  3. Set objCSS = Server.CreateObject("XStandard.CSS2XML")
  4. Set objXML = Server.CreateObject("XStandard.XML2CSS")
  5. Set objDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
  6. objDoc.async = False
  7. Rem - Convert CSS to XML
  8. objCSS.LoadCSS "h1 {color:red}"
  9. Rem - Load XML into parser
  10. objDoc.LoadXML objCSS.XML
  11. Rem - Change the color
  12. Set objNode = objDoc.selectSingleNode("/css/rule[selector = 'h1']/declaration[property = 'color']/value")
  13. If Not objNode Is Nothing Then
  14. objNode.Text = "green"
  15. End If
  16. Rem - Convert XML to CSS
  17. objXML.LoadXML objDoc.documentElement.XML
  18. Response.Write objXML.CSS
  19. Set objCSS = Nothing
  20. Set objXML = Nothing
  21. Set objDoc = Nothing
  22. Set objNode = Nothing
  23. %>