Updating the Text of a Sample Document

When you update an XML document in the Text view of the XML editor, you can use the usual editing tools, as well as tools tailored for handling XML.

Each of the following topics contains instructions for editing a sample XML document. You should perform the steps in each topic before you move on to the next topic. After the first topic, some steps depend on actions you performed in a previous topic.

For more information on editing tools and features, see Using the Text Editor.

This section provides instructions for

Displaying Line Numbers

Stylus Studio lets you optionally display line numbers in most of its editors. Line numbers provide simple, unobtrusive points of reference that can make working large or complex documents easier. Line numbers are off by default; turn them on now.

To display line numbers:
1. Select Tools > Options from the Stylus Studio menu.

Stylus Studio displays the Options dialog box.

2. Click Application Settings > Editor General.

Figure 5. Sense:X and Other Editor Features are in the Options Dialog Box

3. Select XML Editor from the Editor drop-down list.
4. Click Show line numbers.
5. Click OK.

Adding Elements in the Text View of a Sample Document

To add elements in the Text view of your-quotes.xml:
1. In the XML editor window, click in the first line just after <ticker>.
2. Press Enter and type <quote><company>data</.
Sense:X Auto-Completion

As soon as you type the closing forward slash, Stylus Studio displays company> because it is the only element that is appropriate to close. Automatic closing of open tags is part of Stylus Studio's Sense:X intelligent editing. You can change this and other Sense:X options on the Editor General page of the Options dialog box - for example, you can have Stylus Studio display a list of appropriate elements, even if that list includes one only item.

This document does not have a DTD or XML Schema associated with it. But suppose for a moment that it does have an associated schema. As soon as you type <, Stylus Studio would display a pop-up list of the elements you could add at that location. You need only double-click the element you want to add.

Figure 6. Example of Stylus Studio Sense:X

Copying and Pasting in the Text View of a Sample Document

This topic is part of a sequence. If your-quotes.xml is not open, see Opening a Sample XML Document. The sequence starts with Adding Elements in the Text View of a Sample Document.

To copy and paste elements in the Text view of your-quotes.xml:
1. Use the mouse to select the text for one quote element and its contents.
2. In the menu bar, select Edit > Copy.

Alternatives : Press Ctrl+C or click Copy.

3. Scroll down in the XML editor and click just before </ticker>.
4. In the menu bar, select Edit > Paste.

Stylus Studio copies the quote element here, but the indentations are not quite right. Instructions for fixing this are in the topic Inserting Indents in the Text View of a Sample Document.

Alternatives: Press Ctrl+V or click Paste. .

Undoing Operations in the Text View of a Sample Document

This topic is part of a sequence. If your-quotes.xml is not open, see Opening a Sample XML Document. The sequence starts with Adding Elements in the Text View of a Sample Document.

To undo operations performed on the your-quotes.xml document:
1. In the menu bar, select Edit > Undo to remove the text you just pasted.

Alternative: Press Ctrl+Z.

2. In the menu bar, select Edit > Redo to replace the text you just removed.

Alternative: Press Ctrl+Y.

3. In the XML editor window, click Indent XML Tags , which is the left most button.

Stylus Studio displays a message that alerts you that there is an open tag for a quote element but no close tag. The messages indicates the line and column in which the error was found.

4. In the alert box, click OK. Because the document is not well-formed XML, Stylus Studio does not insert indents in the document. The next topic, Inserting Indents in the Text View of a Sample Document, shows how to fix the document so that it is well-formed.
5. In the menu bar, click Edit.

The Undo and Redo operations are no longer active. After you click the Indent XML Tags button, you cannot automatically undo or redo recent changes. It does not matter whether or not Stylus Studio actually inserts the indents. After you make another change, the Undo operation becomes active again.

Inserting Indents in the Text View of a Sample Document

This topic is part of a sequence. If your-quotes.xml is not open, see Opening a Sample XML Document. The sequence starts with Adding Elements in the Text View of a Sample Document.

To insert indents in your-quotes.xml:
1. In the XML editor tool bar, click Indent XML Tags again.

Stylus Studio displays the message that indicates that a close tag is missing. It specifies the element name, and the line and column numbers that identify where the error was found.

2. In the alert box, click OK.

Stylus Studio moves the cursor so that it appears immediately after the quote tag that has no closing tag.

Tip

 

The current cursor location within the document is displayed as line/column coordinates in the Stylus Studio status bar at the bottom of the Stylus Studio window.

Figure 7. Document Position DIsplayed in Status Bar

3. In line 2, click after the </company> tag and type </. By default, Stylus Studio displays quote> because it is the only element that is appropriate to close.
4. In the XML Editor tool bar, click Indent XML Tags .

This time, Stylus Studio correctly indents the XML text.

Indent XML Tags changes your XML document by inserting white space. If this is undesirable, and you want to check for well-formedness, click the Tree tab at the bottom of the XML Editor window. If the document is well-formed, Stylus Studio displays the tree representation. If the document is not well formed, Stylus Studio displays a message that indicates the reason the document is not well formed and the location of the error or omission.

Querying in the Text View of a Sample Document

You use the XPath Query Editor to query XML documents using XPath. Stylus Studio supports both XPath 2.0 and 1.0. The default is XPath 2.0.

The XPath Query Editor is a dockable window that appears to the right of the XML document window. If you do not see it, click the Show XPath Query Editor button ( ).

Figure 8. XPath Query Editor

This topic is part of a sequence. If your-quotes.xml is not open, see Opening a Sample XML Document. The sequence starts with Adding Elements in the Text View of a Sample Document.

To query your-quotes.xml:
1. Click the Query 1 tab in the XPath Query Editor.
2. Type /ticker/quote and click the Execute Query button ( ).

Stylus Studio runs the /ticker/quote query on your-quotes.xml, and displays the results at the bottom of the XPath Query Editor window.

3. In the Query Output window, expand the second quote element to view its contents.
4. Click the symbol element.

In the Text view, Stylus Studio uses its back-mapping feature to move the cursor to the source element for the symbol result element you clicked.

Figure 9. Backmapping from XPath Query Result to XML Document

5. In the Text view, click the down arrow to the right of the query field.
6. In the XPath Query Editor window, click the New Query button ( ).

Stylus Studio adds a new tab for each query you define.

7. Type //company and click the Execute Query button ( ).

Stylus Studio runs the new query and displays the results.

8. Close the XPath Query Editor window by clicking the x in that window's upper right corner.

Deleting and Saving Queries

You cannot explicitly delete a query. In addition, queries you define are not saved with an XML document unless that document belongs to a Stylus Studio project - if you close the XML document and then reopen it, the queries you defined in the previous editing session are no longer there.

For more information

See Using the XPath Query Editor to learn more about the XPath Query Editor.

See Working with Projects to learn more about projects and their role in Stylus Studio.

 
Free Stylus Studio XML Training: