Speaking as a Sitecore developer, XML files have the tendency to become so large that it’s tricky to figure out where exactly you’re working, seen from an XPath perspective. This makes the process of creating e.g. Sitecore include files tedious and error prone.
A while ago I created a small Visual Studio plugin which keeps track of the XPath matching your cursor position when working in files containing XML-markup (e.g. Web.config, NAnt files, MSBuild files, Solr configuration files, Spring.NET files … you get the point). I’ve recently released v3 of the plugin and thought it was about time to do a new writeup of the features.
The plugin can be installed either by downloading it from the Visual Studio Gallery (http://visualstudiogallery.msdn.microsoft.com/c06c7b10-41c3-4aa9-8707-570eb9d879e6) or by opening “Tools -> Extensions and Updates…” and searching for “XPath”.
The source code can be found at https://github.com/uli-weltersbach/XPathInformation.
The XPath matching the current caret position is shown in the Visual Studio statusbar:
Copy XML structure
The basics for a Sitecore include file can be created easily with the “Copy XML structure” command. Simply select an element and choose “Copy XML structure” from the context menu:
xmlns:patch="http://www.sitecore.net/xmlconfig/" is not added to the root automatically.
It’s possible to copy the XPath at the current caret position in 3 different ways:
- Generic – matches one or more elements
- Absolute – matches the current element by index
- Distinct – attempts to determine an XPath which only matches the current element by using distinct attribute values of the current node and its ancestors
It’s possible to configure which attributes are copied to the clipboard from the XPath options page found in “Tools -> Options -> XPath Information”. Check the option descriptions for details.
For personal use I’ve configured the attributes “id”, “name”, “type” and “method” to be used in distinct paths, as these make most sense (to me) when working with Sitecore. This way I can quickly copy the correct XPath to the clipboard when using e.g. “patch:before” in Sitecore include files.
Please use https://github.com/uli-weltersbach/XPathInformation/issues for feature requests and bug reports.
If you find the plugin helpful please rate it on Visual Studio Gallery. 🙂