Summary
XPath expressions are found embedded within XML files such as XSLT stylesheets or Schematron schemas. Two approaches can be taken to extract such XPath expressions (and associated data) and import them into SketchPath for testing or further development:
- Convert XPath expression XML source to the XML structure that is the standard SketchPath library format. This can probably be done most conveniently using XSLT
- Write special XPath expressions that extract data for each XPath expression to be imported
Converting XML Source file to SketchPath Library File
The SketchPath library files are stored and loaded in the form of serialized ADO.NET DataTables. The structure is not yet documented but can be be best discovered by saving a SketchPath library with a few expressions and viewing the XML created.
Importing XPath expressions using XPath Expressions
To actually use one XPath expression (or more, if other attributes are required) to import others may appeal. The main steps for setting up for this approach are:
- Open the XPath expression source XML file in SketchPath
- Create a new expression group by clicking 'New Group' on the expression editor toolbar.
- Use the XPath editor in SketchPath to write an XPath expression that produces a nodeset containing the XPath expressions, save this expression.
- (Optional) Use the XPath editor to write one XPath expression for each other data field related to the XPath expressions that you wish to use, possible fields are: name, group, comment, context. Save each XPath expression. (Note that the order of results must be the same for each nodeset result)
- Rename each XPath expression created according to the library field that it is intended to populate. Use a non-capititalized name corresponding to the field to be populated. Names are expression, name, group, comment and context.
- Use the SketchPath expression manager to rename the group containing the named expressions to 'import'.
- From the main menu bar, select File > Import XPath Expressions
- The expression manager will now show that the expressions have been imported from the XML source. The name, group name, context and comment for each expression should be shown. If no name or group name was specified using an XPath expression then, each name is numbered and prefixed with 'expr-', (eg. expr-22) and the group name set to 'external'.
- Once there is confidence that the XPath expression(s) import correctly, save these in a library so that they can be reused to import other XPath expressions from the same format in the future.
Using an 'Import' library to import XPath expressions from a new XML Source
- Open the XML source file in SketchPath.
- Open the previously created Import Library (as described above) into the SketchPath expression manager.
- Click File > Import XPath Expressions from the main toolbar
- Open the XML source file in SketchPath to use the newly imported expressions against