# Loading and Saving XML Files

> Load and save XML with the Load and Save methods: DTD validation, XMLInvalid and XMLNotWellFormed events, CSS formatting styles and the XML editor mode.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control ActiveX > Document Editor > Working With XML Files > Loading and Saving XML Files
- **794 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/load-save/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/load-save/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/load-save/llms-full.txt

---

`TXTextControl` has built-in features for editing and manipulating XML files, and it loads and saves them like any other file, with the [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) and [Save](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/save-method/llms-full.txt) methods and the XML format (10). What happens during loading depends on the document: whether it is well-formed, whether it matches its document type definition (DTD) and whether a CSS file with formatting styles belongs to it.

Read on for the three results a load can have, the events that report errors and what a save writes to the XML file and to the CSS file.

### How an XML File Is Loaded

When `TXTextControl` loads an XML file, it reads the DTD that belongs to the document and validates the document against it. A DTD, the document type definition, holds the rules for the elements an XML document may contain and how they are ordered and nested. The result decides how the document can be edited:

| The document is | Event | What `TXTextControl` does |
|---|---|---|
| Valid according to its DTD | None | Loads the text and the formatting styles and switches to the XML editor mode |
| Invalid: it doesn't follow the rules of the DTD | [XMLInvalid](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/xmlinvalid-event/llms-full.txt) | Loads the text and the formatting styles; the document can be edited as a normal text document with all editing features |
| Not well-formed: it contains invalid XML syntax | [XMLNotWellFormed](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/xmlnotwellformed-event/llms-full.txt) | Doesn't load the document |

- **The XML editor mode** keeps the document valid while it is edited. [Editing XML Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/editing/llms-full.txt) describes how it works, and the [XMLEditMode](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/xmleditmode-property/llms-full.txt) property tells whether `TXTextControl` is in this mode.
- **An invalid document** is loaded, but the reference of the `XMLInvalid` event adds that it cannot be handled or saved as an XML document.
- **Both events** pass the position in the file where the error occurred and the reason for the error to your application.

### Formatting Styles From the CSS File

An XML file holds no formatting. During loading, `TXTextControl` looks for the formatting styles in the CSS file that belongs to the document. If it finds the file, it loads the styles and displays the document with all its formatting attributes, and all further editing and manipulation of the document takes place in WYSIWYG mode. [XML Basics](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/basics/llms-full.txt) shows an XML file, its CSS file and its DTD side by side.

### Insert an XML Document Into Another Document

An XML document that is inserted into another, existing document becomes invalid. For this reason, `TXTextControl` doesn't load an XML document when the *CurSelection* parameter of the [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) method is set to `True`, which would insert the file at the current input position.

### Save an XML Document

The [Save](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/save-method/llms-full.txt) method saves only the text of an XML document into the XML file. To save the formatting styles of the document into its CSS file, call `Save` a second time with the CSS format (11).

`TXTextControl` has the following limitations:

- Changing and saving the DTD of a document isn't supported.
- Creating a completely new XML document isn't supported.

### Next Steps

- [Editing XML Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/editing/llms-full.txt): the XML editor mode, selections and formatting styles.
- [Programming XML Documents](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/programming/llms-full.txt): reading, changing, inserting and deleting elements in code.
- [XML Basics](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/basics/llms-full.txt): a sample program with an XML file, a CSS file and a DTD.

---

## Nearby

- **Previous:** [Working With XML Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/llms-full.txt)
- **Next:** [Editing XML Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/editing/llms-full.txt)
