Introduction
Auto-Generating an XPath location may prove extremely useful, but because there are a number of ways to express a location path in XPath, the generated path is normally just a starting point and should be edited to meet the exact requirements.
The descriptions below describe what XPath is generated in what context, but when using SketchPath itself this will quickly become apparent, so the text below is really for reference only.
Location Bar
In SketchPath, ignoring for the moment the Namespace Manager Pane, whenever one of the 5 panes linked to the Source XML is selected, the location of the selection is dynamically generated and shown on the XPath location bar above the XPath Editor.
XPath Editor
As you type expressions in the XPath Editor and they are resolved, either automatically or manually (according to the mode set), the first node in a node set is automatically selected. The XPath in the location bar immediately above the XPath Editor therefore shows the path of this first node of the most recent nodeset returned.
XPath can be copied and pasted from the location bar into the XPath Editor at any time. Also, an XPath location can be directly inserted into the XPath Editor by double-clicking either the Element Tree or the Element Node Pane.
Selecting the Location
The generated XPath location, for a single-click will always be that of an element, even if an element child node is selected. If the child node selected is an attribute, the final predicate of the location path is an equality test of the selected attribute and its value.
To remove the potential for ambiguity, position predicates (in abbreviated XPath) are used for elements in the location path that have preceding-siblings with the same name.
A final predicate in the path is added if an XML node is selected on any pane except the Element Tree. This predicate is an equality test on the value of the selected element or attribute.
Sample Generated XPath Location Paths and the context in which they are generated:
Element Selected from Element Tree
/
w:document/w:body/w:p[1]Element Selected from XML Editor, XPath Editor, Result Pane, Expression or Variables Pane
/
w:document/w:body/w:p[1]/w:r[1]/w:t[. ='This is a test']Attribute Selected from XML Editor, XPath Editor, Result Pane, Expression or Variables Pane
/
w:document/w:body/w:tbl/w:tr[5]/w:tc[5]/w:p/w:pPr/w:cnfStyle[@w:val='000000000000']Double-Clicking the Location
Double-Clicking an XML location in the Element Tree or Element Nodes pane, as well as modifying the 'Selected Node' display, also inserts a location path into the XPath Editor itself. This location path differs in that it may be either an element or attribute path depending on the node that is double-clicked.
Element Text-Node Double-Clicked from Element Nodes Pane
/
w:document/w:body/w:p[2]/w:r[1]/w:tAttribute Double-Clicked from Element Nodes Pane
/
w:settings/w:characterSpacingControl/@w:val