Document Content
Editing content in Grid View is straightforward: Double-click inside the content field and edit the content as required. The node type can be quickly changed by clicking the node's Type icon and selecting another type from the menu that appears. In XML documents, entities can be inserted via the Entities entry helper. Grid View additionally offers validation and find-and-replace functionality.
This topic describes the unique Grid View features of XML and JSON documents. For a description of the Grid View features of DTD documents, see the DTD topic.
Type selection (XML)
The cells in Grid View contain nodes of the XML document. We have grouped the types as follows:
•Name–Value types: Element, attribute, processing instruction (PI). Nodes of this type have names and values.
•Value types: Text, CDATA, comment, entity/character references. Nodes of this type take values only.
•Definition types: XML declaration, DOCTYPE (internal or external DTD). These nodes define properties of the XML document.
•Special container types specific to XMLSpy: Formula.
The type of a value is indicated by a symbol in front of the value (see screenshot below). To change a type, click its symbol and select the type you want from the menu that appears. Alternatively, right-click in a cell and, from the context menu that appears, select a type from the Type sub-menu. The symbols and shortcuts of types are shown in the screenshot below:
Note the following points:
•Nodes of type Element, Attribute, and PI take a name and a value, whereas nodes of type Text, CDATA, and Comment take only a value. For example, an element node will have a name and content, whereas a text node will have only a value.
•Type conversions try to preserve the original key and value. For example, if you convert an element to an attribute, the attribute will have (i) the same name as the element, and (ii) a value that is, as far as possible, the same as the content of the element.
•In the sequence of an element's child nodes, attributes are always listed first. As a result, type conversions could lead to a reordering of nodes.
•In the case of mixed content (character data interspersed with element children, such as a paragraph element that contains text as well as bold and italic elements), consecutive text nodes are not allowed and so might automatically be joined.
•You can set an option to determine whether, when multiple nodes are selected for conversion to a single type, this change should go ahead or not, or whether you should be warned.
•You can edit raw text in a cell or a row by selecting the parent cell or parent row to be edited in this way and then clicking the Edit as Raw Text icon in the toolbar. When you edit text as raw text, entities and markup in that cell or row will not be resolved, respectively, into glyphs and Grid View components (and can therefore be edited).
Type selection (JSON/YAML)
JSON Grid View distinguishes the following type categories:
•Simple types: String, Number, Boolean, Null
•Special simple types: Auto (which is detected from the value), Comment (JSONC, JSON5, YAML)
•Container types: Object, Array
•Special container types: Formula
•YAML type: Alias
The type of a value is indicated by a symbol in front of the value (see screenshot below). To change a type, click its symbol and select the type you want from the menu that appears. The symbols and shortcuts of types are shown in the screenshot below:
Auto-detected types have green dots under them (see screenshot below). An explicit type is a type that you assign.
Type-related actions occur in two situations:
•When a JSON document is loaded: All simple types are converted to Auto, which are automatically detected from the values. For example "MyString" is automatically detected as a String type, 123 as a Number type, true as a Boolean type, and null as a Null type. In cases of ambiguous strings, select the type explicitly.
•When a new data structure or value is entered: Simple types are auto-detected and the type is automatically assigned. You can change the type subsequently if you want to.
Note: | The JSON Grid View settings enable you to specify (i) how type changes are to be handled when multiple cells are selected, and (ii) how values of atomic types should be treated when the type is changed to an array or object. |
Auto-completion
Auto-completion is enabled when the document being edited is associated with a schema.
Auto-completion provides you with entry options at the cursor location (see screenshot below). These options, which are based on the definitions in the schema, are provided (i) via pop-ups in the main window, and (ii) via the entry helpers. The pop-ups and entry helpers each display a list of entries that are valid at that cursor location. To move through the entries in the pop-up list, use the arrow keys. Select an entry from the pop-up window or double-click an entry in the entry helper to insert it.
For JSON and YAML documents, note the following points:
•If the document is a JSON schema, then auto-completion is based on the schema version indicated by the $schema keyword. For more information, see also JSON Schema Version.
•If the document is a JSON/JSON5 or YAML instance, then a JSON schema must be assigned to the instance in order for auto-completion to be enabled.
Validate on modification
The Validate on Edit mode is toggled off by default. When toggled on, well-formed checks and validation checks are carried out as you edit a document in Grid View. For validation to be carried out (additional to well-formed checks), a schema must be assigned to the document. Errors are shown by (i) displaying erroneous text in red and (ii) flagging the location with a red exclamation mark. If a smart fix is available for an error, then a light bulb icon is shown on the line that generates the error. When you place the mouse over the icon, a popup appears that lists available smart fixes. Select a fix to apply it immediately. For more information, see Validating XML Documents and Validating JSON Documents.
The Validate on Edit mode can be toggled on/off either (i) via the XML | Validate on Edit menu command, (ii) the Validate on Edit toolbar button, or (iii) via the On Edit option of the Validation settings of the Options dialog.
Find and Replace
The Find (Ctrl+F) and Replace (Ctrl+H) commands (accessed via the Edit menu or Ctrl+F) provide powerful search capabilities. The search term can be narrowed down in terms of casing and whether whole words should be matched, and it can also be expressed as a regular expression. The search range can be restricted to a selection in the document. Results are highlighted in orange, and containing cells also highlighted in orange.
For a description of the Find and Replace functionality, see the descriptions of the Find and Replace commands of the Edit menu.