Loading and Saving XML Files

TX Text Control offers several built-in features to edit and to manipulate XML files. XML files can be loaded and saved like all other files using the Load and Save methods.

When an XML file is loaded TX Text Control considers the corresponding document type description file (DTD) and checks the document for validity. If the document is invalid (which means that it does not fulfill the rules in the DTD), a TextControl.XmlInvalid event occurs. However, the document's text including its formatting styles is still loaded. The document can then be edited as a normal text document with all the editing features TX Text Control offers.

Otherwise, if the document is valid according to the corresponding DTD, Text Control loads the document's text and formatting styles and switches to a special XML editor mode which guarantees that the document remains valid during editing. This article describes how the XML editor mode works and how an application can manipulate an XML document. The TextControl.XmlEditMode property informs about the state of the XML editor.

If an XML document is not well-formed (which means that it contains invalid XML syntax) a TextControl.XmlNotWellFormed event occurs and the document is not loaded. Both the XmlInvalid and the XmlNotWellFormed event informs the application about the positon in the file where the error occurs and the cause of the error.

During loading, a Text Control looks for corresponding formatting styles contained in a CSS file. If such a file is found, the styles are loaded and all formatting attributes are displayed. All further editing and manipulation of the XML document can be performed in WYSIWYG mode.

Because an XML document becomes invalid if it is inserted into another existing document, XML documents cannot be loaded or saved with the Selection.Load and the Selection.Save methods.

If an XML document is saved using the TextControl.Save method, only the document's text is saved to the XML file. To save the document's formatting styles to the corresponding CSS file, a second call of the TextControl.Save method must be performed. Changing and saving the document's DTD is not supported. Neither is it supported to create completely new XML documents.