5.1. The "XML source" menu item

This menu item is available only when the "Edit source" add-on has been installed.

The "Edit source" add-on adds an "XML Source" item at the end of the View menu. Selecting this item replaces the current styled or tree view by a source view of the document being edited.

The source view of a document shows the contents of the save file which would be created by XXE for this document (same automatic indentation, same named character entities, etc).

The source view of a document embeds an advanced text editor having the following capabilities.

  • Syntax highlighting.

  • Element folding.

  • Auto-completion (after pressing Ctrl+SPACE) for element names, attribute names, attribute enumerated values and named character entities.

  • "Not well-formed" errors are reported in really time.

Limitations:

  • Validity errors are not reported in really time.

  • Auto-completion suggests all the child element names regardless of whether this would make the parent element invalid. For example, auto-completion will suggest child element title even when the chapter parent element already has a title.

In addition to the keyboard shortcuts found in all text editors, the source view also supports the following shortcuts:

Keyboard ShortcutDescription

Ctrl+SPACE

(Ctrl even on the Mac)

Auto-completion for element names, attribute names, attribute enumerated values and named character entities.

Ctrl+F

(Cmd on the Mac)

Find.

Press Ctrl+Shift+F to find backwards.

Ctrl+G

Find again.

Press Ctrl+Shift+G to find again backwards.

Ctrl+M

Replace.

Press Ctrl+Shift+M to replace backwards.

Ctrl+Shift+L

Goto line.

The source view is not “synchronized in real-time” with the other views of the same document

Being an (almost) normal view of an XML document, it's possible to use ViewMultiple ViewsAdd View to have, for example, the styled view of a document and its source view side by side.

However, while all the tree and styled views of a document are “synchronized in real-time” (that is, reflect the same document content in real-time), this is not the case of the source view. For performance reasons, you'll have to save the document to disk (or at least check the document for validity) to synchronize a source view with the other views.

For example, if you click in the styled view of a document (left side in the above figure), modify it and save the document to disk, the source view of the document will be automatically updated. Note that if before doing that, the source view was modified, you'll loose these unsaved changes.

Conversely, if you click in the source view of a document (right side in the above figure), modify it and save the document to disk, the styled view of the document will be automatically updated. Note that if before doing that, the styled view was modified, you'll loose these unsaved changes.

In a nutshell, if you use the styled view of a document side by side with other views, always remember to save your document to disk (Ctrl+S; or at least check the document for validity: Ctrl+Shift+V) before switching from one view to an other.