SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

August 2006 - Posts

  • Go To XML Schema Definition

    The XML Editor in SharpDevelop 2.1 now has Go To XML Schema Definition support. Open an XML document that uses a schema into SharpDevelop, move the cursor to the element or attribute, then either right click and select the menu option Goto Definition or press Ctrl+Enter. The schema will then be opened and the cursor will be positioned on the matching element or attribute definition.

    Features

    • Go to element definition.
    • Go to attribute definition.
    • Go to attribute, element, attribute group and group references.
    • Go to referenced simple type, complex type.

    Go To Element Definition

    Move the cursor so it is on the element name inside its starting tag. Right click and select Goto Definition or press Ctrl+Enter.

    Go to definition menu item

    The schema will then be opened and the cursor moved to the element definition.

    Wix Schema showing product element

    Go To Attribute Definition

    Move the cursor so it is inside or next to an attribute.

    Cursor next to Wix document Product/@Id attribute

    Go to definition takes you to the attribute definition.

    Wix schema product/@Id displayed

    Go To Element Reference

    Inside the schema itself, move the cursor inside the ref attribute's value.

    Cursor on WiX schema element ref

    Go to definition takes you to the referenced element.

    WiX Schema showing AppId element

    Similarly you can click inside the ref attribute value for the elements xs:group, xs:attributeGroup, and xs:attribute, and go to their corresponding definitions.

    Go To Element Type

    Inside the schema, move the cursor inside the type attribute's value.

    Cursor inside element type attribute.

    Go to definition takes you to the corresponding complex type.

    WiX schema with complex type displayed

    Go To Attribute Type

    Inside the schema again, move the cursor inside the type attribute's value.

    Cursor inside type attribute's value.

    Go to definition takes you to the type definition.

    Wix schema simple type displayed

    Navigating Back and Forward

    Used in conjunction with the new Navigate BackNavigate Back toolbar button and Navigate ForwardNavigate forward toolbar button toolbar buttons, added by David Alpert, you can quickly jump back and forth around the schema.

    Limitations

    It only works with schemas that SharpDevelop is aware of. These can configured by selecting Options from the Tools menu, then selecting the Text Editor category and then XML Schemas.

    SharpDevelop does not currently pick up any changes made to a schema without being restarted.

  • XPath Queries

    SharpDevelop 2.1 now has an XPath Query window where you can run an XPath query on the active XML document and the matched nodes will be highlighted.

    Features

    • Shows a list of XML nodes matched by the XPath query.
    • Highlights the matched XML nodes in the XML Editor.
    • Namespaces supported.

    Running an XPath Query

    Open an XML document in SharpDevelop. For this walkthrough I am going to use the following WiX document.

    <?xml version="1.0"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi">
        <Product Id="21BF5D59-D3AD-46FC-97B2-A3DD23A5BE20"
            Name="Your Application"
            Language="1033"
            Version="1.0.0.0"
            Manufacturer="Your Company">
     
            <Package Id="8874187C-94B0-4DB4-9B73-E4D635680BA3"
                Description="#Description"
                Comments="Comments"
                InstallerVersion="200"
                Compressed="yes"/>
      
                <Property Id="AcceptLicense">No</Property>
                <Property Id="Button_Back">&lt; &amp;Back</Property>
                <Property Id="Button_Next">&amp;Next &gt;</Property>
                <Property Id="Button_Finish">&amp;Finish</Property>
                <Property Id="Button_OK">OK</Property>
                <Property Id="Button_Cancel">Cancel</Property> 
                <Property Id="Button_Exit">&amp;Exit</Property>
         </Product>
    </Wix>

    From the View menu, select Tools and then select XPath Query.

    XPath Query menu item

    This opens the XPath Query window.

    XPath Query Window

    If your XML document has any namespaces that you need to refer to in the XPath query you can add them to the Namespaces tab. In the image below the WiX namespace has been entered along with a prefix.

    WiX namespace added to XPath Query namespaces

    The prefix cannot be an empty string even for an XML document that does not use explicitly use a namespace prefix (e.g. like the WiX document we are currently using).

    Type in your query into the XPath text box and then either click the Query button or press the return key to execute the query and show the results. The results are displayed as a list in the XPath Query window and the corresponding nodes in the XML document are highlighted.

    XPath query results

    Double clicking a row in the Results list will jump to the corresponding XML line and sets focus back to the XML Editor. Single clicking a row will cause the XML Editor to scroll to the matched node.

    If the XPath you typed in has an error this information is displayed in the Results list when you try to execute the query.

    XPath query error

    Any errors in the XML document are also displayed in the Results list when you attempt to execute the query.

    Xml document errors

    To remove the highlighting in the XML document, right click the document and select Hide XPath Results.

    Hide XPath results menu item

    Visual Studio

    If you want to do same thing in Visual Studio 2005 then take a look at XPathmania created by Don Demsak.

Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.