Home > Online Product Documentation > Table of Contents > Updating XML Documents Using the Grid
The Grid view of an XML document is useful for structured data - it is a convenient way to view and work with documents that contain multiple instances of the same type of element.
This section describes the features of the Grid tab and how to use it to edit XML documents. This section covers the following topics:
This section describes the layout and features of the Grid tab. It covers the following topics:
The Grid tab consists of a tool bar and a display area. The tool bar has buttons to perform actions and operations on both the grid itself and on the underlying XML document represented in the grid. An example of the former is the ability to show the child elements of the document's root element; they are hidden by default. An example of the latter is the ability to add a new instance of an element or to change a value. These operations are also accessible from the XML > Grid Editing menu, as well as from the grid shortcut menu (right-click on the grid).
The tool bar also includes a query field, which allows you to enter an XPath expression to query the XML document. Results are displayed in the Query Output window, which appears when you run the query if it is not already displayed. See Querying XML Documents Using XPath for more information on this feature.
The display area shows the XML document, both its structure and content, rendered in a tabular, or grid format.
When you first display a document in the
Grid tab, the document is collapsed so that it shows just the root element (here it is
<books>) and its name attribute (
My books), as shown in
Figure 117.
A plus sign displayed to the left of the node name indicates that this node has child nodes. You can click the plus sign to display a subgrid that displays the child nodes, as shown in Figure 118.
You can continue to drill down in this fashion to view all values.
Some nodes in a document are simply containers - they have no content of their own. An example of a container node is the
<authors> element in
books.xml. The
<authors> element is simply a container for one or more
<author> elements, as shown in this excerpt of
books.xml:
To streamline the display, Stylus Studio hides the tables that represent container nodes. Information about container nodes is displayed in the child node's header.
Figure 119 shows the default display for the
author element. Notice that the header,
book/authors/author, contains information about the container node,
authors.
If you want, however, you can display the tables associated with container nodes, as shown in Figure 120.
The table associated with the
authors node now appears in the grid; it is empty (it has no rows) because it is a container. The elements it contains are displayed in their own table,
authors/author.
This action is also available from the XML > Grid Editing menu and from the grid shortcut menu.
You can rename container nodes directly in the grid.
The node name is selected.
When you expand a node, Stylus Studio displays it in uniform columns. You can resize columns to any width you prefer by dragging the handle on the right side of the column header, as shown in Figure 121.
In the grid view of a structured XML document, each child element of a node corresponds to a row in a table. For example, the
<books> node of
books.xml contains nine child elements; each row is an instance of the
<book> element. To preserve space in the grid, the tag names of child elements are not displayed as a separate column in the table. Rather, as shown in
Figure 118, this information is displayed in the table header itself.
If you want, you can display the tag name for child elements in their own columns, as shown in Figure 122.
This action is also available from the XML > Grid Editing menu.
You can move around the grid using the mouse (click where you want to go) and the keyboard. Keyboard navigation is presented in the following table.
When you select a cell in a table:
When you make a change to the document structure or content on the Grid tab, those changes are reflected immediately in the underlying XML document. You can see your changes affect the document on the Text tab.
Consider the following excerpt from
books.xml.
If you move the rows in the authors table, for example, as shown in Figure 123,
the underlying XML changes accordingly:
The following changes, all of which can be made using Grid tab, affect the underlying XML document:
Changes you make affect the current instance only. For example, in the example shown in
Figure 123, only that instance of the nested table is affected. If you add a column to
books/book, however, every instance of
books/book gets that new column.
Stylus Studio provides several features to help you work with table rows in the Grid tab. Changes you make to tables in the Grid tab, such as adding a new row or modifying a value, are reflected in the underlying XML document.
This section covers the following topics:
You can move rows up and down within the same table. Changes you make to row order affect the element order in the underlying XML document.
You can add and delete rows in a table. Changes you make to the table in this way affect the number of instances of the element in the table. When you add a row, you can insert it in the table above or below the currently selected row.
The row is added to the table.
The row is deleted from the table.
Stylus Studio provides several features to help you work with table columns in the Grid tab. Changes you make to tables in the Grid tab, such as adding a new column or reordering existing columns, are reflected in the underlying XML document.
This section covers the following topics:
Column operations can be performed when you select any cell in a column. When a cell (and, therefore, its column) is selected, it is highlighted with a yellow outline. As shown in
Figure 124, the
<title> column is selected - the cell containing
Java Message Service is the one that is highlighted.
You can add two types of columns to tables in the Grid tab - attribute columns and element columns. The procedure for adding both types of columns is the same. When you add a column, it is inserted immediately after the last column of its type. You can move columns after you create them.
The column is added to the table.
A yellow border appears around the cell you select.
The column is deleted from the table.
You can reorder columns in the grid by dragging them to the position you desire.
The cursor changes shape, as shown here.
The column is placed in the new location within the row.
You can rename columns in the grid. This has the effect of renaming the corresponding attribute or element name in the underlying XML document.
A yellow border appears around the cell you select.
The column is renamed.
You can change element and attribute values.
The cell field becomes editable, as shown here.
Stylus Studio provides several features to help you work with tables in the Grid tab. Changes you make to tables in the Grid tab, such as adding a nested table, are reflected in the underlying XML document.
This section covers the following topics:
You add nested tables to a document in the Grid tab using the Add Nested Table dialog box, shown in Figure 127. This dialog box allows you to specify the path to the root for the new table, a row element name, and the number of rows.
A nested table is created as a child of the current element. The nested table shown in
Figure 128,
myTable, was created as a child of the
<book> element.
Nested tables are created with two default rows, which use the element name you provide in the
Row Element Name field of the
Add Nested Table dialog box. Rows get a default text value of
Row n
text, where n is an incrementing value starting with 1. You specify the number of rows using the
Number of rows field.
The Add Nested Table dialog box appears.
The nested table is added to the document and appears in the grid.
You can change the order of nested tables within a row.
The table is deleted from the document.
You can sort tables on any column in ascending or descending order.
The table rows are sorted based on the order you select.
You can copy a tab-delimited text version of a table to the clipboard. This makes it possible to paste document contents from the grid into spreadsheets and other editors that can manage tab-delimited files.
Figure 129 shows
books/book in
books.xml pasted into Microsoft Excel, for example.
Note that when you use this feature, the entire table is copied - column headings (element and attribute names) are not distinguished from cell contents (element and attribute values) in the spreadsheet.