Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Using CSS to format an XML document

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:css_formatting.zip Download [8.34 KB, ZIP]

This code snippet show you how to load an XML document with the corresponding formatting styles contained in the CSS file.

As the corpus of our XML, we are going to use the Shakespeare play Romeo and Juliet which is now public domain text, marked up in XML, provided by Jon Bosak. You can download this text and many other Shakespeare plays at:

It is important that the CurSelection parameter of the Load method is set to false, because an XML document becomes invalid if it is inserted into an existing document. First use the 'File' menu to load the XML document, as shown below:

  1. TXTextControl1.Load CommonDialog1.FileName, 0, 10, False

If the document is valid according to the DTD, TX Text Control loads the content and the style and switches to the new special XML editor mode. This mode guarantees that the document remains valid during editing.

Now you can change the format of the different styles, which can be seen in the first combo box in the button bar. The styles can be also changed programmatically.

  1. Set Style = TXTextControl1.Styles.Item("TITLE")
  2. Style.FontBold = 1
  3. Style.FontUnderline = 1
  4. Style.FontSize = 400
  5. Style.Apply

The above code sets the style item TITLE to bold, underlined and set the font size to 20 points.

Now you can save the new format settings back to the CSS file. You can also change the content of the XML document and save this back to the XML file. After loading the XML document again you will see that your changes has been taken effect.

As ever, we would be delighted to help you with this example. Please post your questions and requests for support into the TX Text Control Support Forum.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place