Loading and Saving XML Files

Technical Articles > Working with XML Files

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 or Save method.

When an XML file is loaded Text Control considers the corresponding document type description file (DTD) and checks the document for validation. If the document is invalid (which means that it does not fulfill the rules in the DTD) an XMLInvalid event occurs, however, Text Control still loads the document's text and its formatting styles. The document can then be edited as a normal text document with all the editing features 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 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) an XMLNotWellFormed event occurs and the document is not loaded. Both the XMLInvalid event and the XMLNotWellFormed event informs the application about the positon in the file where the error occurs and the error's reason.

During loading, Text Control looks for corresponding formatting styles contained in a CSS file. If such a file could be found Text Control loads the styles and displays all formatting attributes. 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, Text Control does not load an XML document if the CurSelection parameter of the Load method is set to True.

If an XML document is saved using the Save method only the document's text is saved into the XML file. To save the document's formatting styles into the corresponding CSS file a second call of the Save method must be performed. Changing and saving the document's DTD is not supported. Text Control also does not support the creation of completely new XML documents.