Home > Online Product Documentation > Table of Contents > Pattern Matching Pattern MatchingYou can use regular expressions to specify match patterns for the rows in the input file. Only those rows in the input file that match the pattern you specify are output to XML when the file is converted. The simplest way to define a match pattern is to use the Match Pattern property in the Row Element Name section of the Properties window. ExampleConsider the following input file:
If you specify a simple regular expression, say,
Note that the match pattern also appears as a new node in the schema pane. This new node, the only one defined for this adapter at this point, uses the default row element name (
Since the match pattern selects only those rows that begin with the letter B, the adapter creates the following XML document when it is run against the input file:
See Working with Nodes to learn about adding the row element name/match pattern pairs that define them. Sample Regular ExpressionsThe following table presents some commonly used regular expressions.
Go to http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html to learn about the specific regular expression implementation supported in Stylus Studio. Go to http://www.boost.org/libs/regex/doc/syntax.html for additional examples of regular expression usage. Specifying Multiple Match Patterns
You can specify multiple match patterns for a single file. If we define a new match pattern,
When you define multiple match patterns, the document pane displays a gray square alongside rows that match a pattern other than the one, if any, associated with the currently selected row. In
Figure 189, for example, row 3 is the currently selected row; it matches the pattern
Working with NodesIn addition to defining nodes using the Match Pattern field of the Properties window, you can also use the Set Node and Match Pattern dialog box, shown here:
This dialog box allows you to
When you open the dialog box, the Row Element Name and Match Pattern fields contain default values that reflect the currently selected row in the document pane or node in the schema pane. Defining a New NodeTo define a new node:
1. Select a row in the document pane or a node in the schema pane.
2. Select
ConvertToXML > Add Node and Pattern from the Stylus Studio menu.
Alternative: Select Add Node and Pattern from the document pane or schema pane shortcut menu. The Set Node and Pattern dialog box appears.
3. Change the default values in the
Row Element Name and
Match Pattern fields.
4. Click
OK.
Cloning a NodeTo clone a node:
1. Select the node in the schema pane that you want to clone.
Alternative: Select the row in the document pane that is represented by a row element name/match pattern pair you want to clone.
2. Select
ConvertToXML > Clone Node and Pattern from the Stylus Studio menu.
Alternative: Select Clone Node and Pattern from the document pane or schema pane shortcut menu. The Set Node and Pattern dialog box appears.
3. Change the default values in the
Row Element Name and
Match Pattern fields as needed.
4. Click
OK.
Editing a NodeTo edit a node:
1. Select the node in the schema pane that you want to edit.
Alternative: Select the row in the document pane that is represented by a row element name/match pattern pair you want to edit.
2. Select
ConvertToXML > Edit Node and Pattern from the Stylus Studio menu.
Alternative: Select Edit Node and Pattern from the document pane or schema pane shortcut menu. Alternative: Double-click the node. The Set Node and Pattern dialog box appears.
3. Change the default values in the
Row Element Name and
Match Pattern fields as needed.
4. Click
OK.
Removing a NodeWhen you remove a node, you are deleting the row element name/match pattern pair from the adapter you are defining. To remove a node:
1. Select the node in the schema pane that you want to remove.
Alternative: Select the row in the document pane that is represented by a row element name/match pattern pair you want to remove.
2. Select
ConvertToXML > Remove Node and Pattern from the Stylus Studio menu.
Alternative: Select Remove Node and Pattern from the document pane or schema pane shortcut menu. Alternative: Press the Delete key. A warning message appears.
3. Click
Yes to remove the node, otherwise click
No.
|