Last week, the XML version of TX Text Control was released -- TX Text Control Enterprise/XML. If you missed the press release, you can view them online in the archived.
Over the next weeks, we intent to present a number of XML applications, showing you how you can get the most out of TX Text Control's XML handling.
This week, we are going to 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:
http://www.ibiblio.org/xml/examples/shakespeare/
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.
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.
Set Style = TXTextControl1.Styles.Item("TITLE")
Style.FontBold = 1
Style.FontUnderline = 1
Style.FontSize = 400
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.
You can get the source code to this example from this zip file.
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.
Best regards
The Newsletter Team