DanSharp XmlViewer

© 2007 Daniel Probert

http://dansharpxmlviewer.codeplex.com

Contents

1. Introduction

2. Viewing an Xml File

2.1 Inheritance and Types

2.2 Browser View

3. Testing XPath Queries

4. Validating against an Xml Schema Document

5. Generating a BizUnit Test Case

6. Other

6.1 Command Line options

6.2 Adding Windows Explorer Right-Click Support

6.3 Clearing the list of Recently Used Xml Files/Schemas

 

History

V1.0

· Initial release

To Do

· Multi-thread the syntax highlighting of XPath Queries

· Multi-thread the processing of new Xml File and Validation of Xsd's

· Test against more examples of large/complex Xml Files

· Inline editing of Xml?

Support

If you have any questions/queries, email me at xmlviewer@probertsolutions.com

1. Introduction

Welcome to the DanSharp XmlViewer!

This is a little utility which I wrote to assist with Xml/BizTalk development.

The tool essentially lets you do three things:

1) Select and test XPath statements against an Xml instance document

2) Validate an Xml instance document against a schema

3) Generate a BizUnit Test Case from a given Xml instance document

There are a lot of commercial tools on the market which do 1) and 2) but...

a) They're not free

b) They require an install (DanSharp XmlViewer is a single exe)

c) The XPath generation leaves a lot to be desired (e.g. Altova's XmlSpy never seems to generate the XPath that I'm after with full local-name() and namespace-uri() values)

d) They don't do 3)!!

Visual Studio gives you the ability to select an XPath statement from a schema file, but not from an Xml instance.

Most of the time I use Stylus Studio to work with XPath – but not all organisations let you install software on their PCs, and I didn't want to have to buy a copy.

2. Viewing an Xml File

To use DanSharp XmlViewer you first need to open an Xml file.

You can do this in one of three ways:

1) Use the File\Open... menu

2) Select a recently used file from the File menu

3) Drag an Xml file onto the application

clip_image002_thumb

clip_image004_thumb

When you open an Xml file, you will see the file displayed in a Tree View:

clip_image006_thumb

You can expand each of the nodes in the tree to see the contents.

As you hover over each node, the tool tip tells you the number of attributes, the number of child nodes, the namespace and (if appropriate) the value:

clip_image008_thumb

Attributes are displayed with a "@" prefix and are displayed in brown.

Elements are displayed in black.

If an attribute/element has a value, then after the name there will be a colon and the value:

clip_image010_thumb

If you select a node in the tree, you will see the XPath required to select that node appear in the bottom half of the form. If the element is a repeating element, and there are more than one of them, then the XPath query will automatically include an index:

clip_image012_thumb

You can do a CTRL-A to select all the text in here (useful for pasting into the XPath Queries tab).

2.1 Inheritance and Types

If there are Xml elements in your file which use the xsi:type attribute (i.e. they inherit from a base class) then you will see the type name displayed in square brackets after the element name:

clip_image014_thumb

2.2 Browser View

To see the document displayed in browser view (i.e. as though you had opened it in Internet Explorer) switch to the Xml View tab:

clip_image016_thumb

3. Testing XPath Queries

To test an XPath query against the currently loaded document, switch to the XPath Queries tab.

On this tab, the top half is where you enter your query, whilst the bottom half displays the results.

Type in or paste an XPath query and press Execute:

clip_image018_thumb

Some things to note:

1) As you enter a query in the top half, your syntax is checked. If you enter an invalid query, the text will be highlighted in red.

2) If you select some of the text in the top half, then only this text will be executed – useful if you have multiple queries displayed.

4. Validating against an Xml Schema Document

You can validate the current Xml Document against an Xsd by switching to the XSD Validation tab.

Here you can select an Xsd: use the Select Xsd... button (or use the drop down to select a recently opened Xsd):

clip_image020_thumb

When you have selected a schema, press the Validate button to perform validation of the current Xml file:

clip_image022_thumb

If you choose a schema which does not share any namespaces with the current Xml document (i.e. is unlikely to validate any of the elements in the current document) then you will see a warning:

clip_image024_thumb

If the current Xml document fails to validate, you will see validation errors:

clip_image026_thumb 

5. Generating a BizUnit Test Case

To generate a BizUnit Test Case for the current Xml Document, select Tools\Generate BizUnit Test Case... from the menu.

This will show the BizUnit Test Case window, with the test case displayed.

You can click Save As... to save the current text in the window, or edit the text and save it, or just do a CTRL-A to select the text.

clip_image028_thumb

Note: The BizUnit Test Case will contain:

1) An XPath statement per attribute and element in the Xml Document which has a value

2) An XPath count() statement for any elements which repeat

3) File copy/watch steps using the location of the current Xml Document (meant to be used as a starting point for the test case)

6. Other

6.1 Command Line options

You can run DanSharp XmlViewer from the command line if you wish to generate BizUnit Test Cases or perform Xsd Validation from a batch file or script.

Note: you need to use the command line version (XmlViewer.com) instead of the windows version (XmlViewer.exe) – you can find the command line version in your application install directory. The console app will return an exit code of 0 if there were no errors, and an exit code of 1 if there were errors.

Run XmlViewer.com (with no parameters) to get help on the syntax supported:

clip_image030_thumb

6.2 Adding Windows Explorer Right-Click Support

In the installation folder there is a file called GenerateBizUnitTestCase.reg.

If you double-click this, and select Yes to install into the registry, then when you right-click an Xml file you will get the option to generate a BizUnit TestCase for that file:

clip_image032_thumb

If you have installed DanSharp XmlViewer into anything other than the default directory, then you will need to go into the Registry Editor, navigate to this key:

HKEY_CLASSES_ROOT\xmlfile\shell\GenerateBizUnitTestCase\command

and edit the path in the default value to match your installation path.

Note: this option will always generate a TestCase into the same folder with the name TestCaseFor_(original file name) – this is the same as using the TestCase action from the command line without the second filename parameter.

6.3 Clearing the list of Recently Used Xml Files/Schemas

To clear the list of recently used files, select Tools\Reset Recent File List

Last edited Oct 5, 2011 at 5:12 PM by probertdaniel, version 9

Comments

No comments yet.