XML Notepad 2007 Design Chris Lovett Microsoft August 2006 Summary: This article introduces a new version of XML Notepad. The tool was first introduced in 1998 but has been unavailable for several years. This version leverages System.Xml and adds new features. Contents Design and Implementation Validation, IntelliSense, and Custom Editors Infinite Undo/Redo Unit Testing Conclusion I finally got around to fulfilling a promise I made to a friend at MSDN. Back in 1998, we shipped an XML Notepad, written by Murray Low in C++. Later on it fell behind in support for XML standards and, because we didn't have time to fix it, we pulled it off MSDN. But Murray apparently did such a nice job that MSDN was inundated with requests to put the notepad back up, so MSDN asked me for a replacement. I've been working on System.Xml in C# since 1999, so I figured I could crank out a replacement using the .NET Framework pretty quickly. Well, the problem was it was one of those side projects on my "one-day" list — you know how that goes! Fortunately, a good friend of mine, Michael Corning, took interest in it, helped hold my feet to the fire, and also added some cool features himself. Dan Doris also took pity on me and helped identify some great bugs. So here we are, finally, with something that should be useful to those who want a quick way to view and edit XML documents. For those who know the original version, the interface should look familiar: a tree view on the left synchronized with a node text view on the right and handy nudge toolbar buttons for quick movement of nodes up and down the tree (see Figure 1). Because it's been so long since the first version, I've had to leverage the cool stuff in System.Xml and add some bells and whistles that the original version didn't have: • Incremental search (CTRL+I) in both tree and text views, so that as you type it navigates to the most matched node. • Cut/copy/paste with full namespace support in a simple interoperable XML format. • Drag/drop support for easy manipulation of the tree, even across different instances of XML Notepad and from the file system. • Infinite undo/redo for all edit operations. • In-place, pop-up, multi-line editing of large text node values and IntelliSense based on expected elements and attributes. • Configurable fonts and colors via the options dialog. • Full find/replace dialog with support for regex and XPath expressions. • Good performance on large XML documents (loading a 3 MB document in about one second).

• • • •

Instant XML schema validation while you edit with errors and warnings shown in the task list window. Support for custom editors for date, dateTime, time, and color datatypes. HTML viewer for displaying XSLT transformation results. Built-in XML Diff tool.

Design and Implementation In the downloadable package you'll find the core XmlNotepad dll project, an Application project that builds XmlNotepad.exe, the XmlDiff library projects used in the XML diff feature, a Setup project for building the .msi installer, the UnitTest project for testing XML Notepad, and a Help project for building the Help.chm file using the HTML Help Workshop tools.

Figure 1. XML Notepad interface The following diagram shows the relationships between the main UI classes. The main form contains all the UI elements from the TaskList to the main XmlTreeView with Resizers in between; it's the launching point for the dialogs such as FormSearch, FormSchemas, FormOption, and FormAbout.

Figure 2. Main UI classes The main tab control contains the XmlTreeView and the XsltViewer for showing XSL output. The XmlTreeView contains a TreeView on the left and a NodeTextView on the right and coordinates scrolling between these two views. Both the TreeView and NodeTextView provide the same IntelliSense editing functionality using a TextEditorOverlay component. The XmlTreeView implements IFindTarget, which is used by the Find dialog (FormSearch) to implement find/replace functionality.

Figure 3. Find dialog The Find dialog supports full text, regex, or XPath expressions and can filter by names or values. Here you see the XPath search, which also provides a table for entering namespace prefix mappings used in the query.

Validation, IntelliSense, and Custom Editors The biggest new feature is IntelliSense, which is driven by XML Schema information provided via the SchemaCache. For example, if your element or attribute is defined by an XSD simpleType and this simpleType contains a list of enumeration facets, then you will get a drop-down like this:

Figure 4. Drop-down list values The way this works is that the Checker runs after each edit operation to validate the document and report errors in the TaskList. This process also puts System.Xml.Schema.XmlSchemaType information on each element and attribute in the XmlDocument; then, when editing the value of that node, the TextEditorOverlay uses the XmlIntelliSenseProvider to get back a list of possible values. In the above example it returns the values from the simpleType enumeration facets. For element name IntelliSense in the tree view, the XmlIntelliSenseProvider invokes the Checker again, captures GetExpectedParticles and GetExpectedAttributes on the System.Xml.Schema.XmlSchemaValidator, and uses that to provide IntelliSense.

Figure 5. IntelliSense in tree view The TextEditorOverlay also supports custom editors like the DateTimeEditor or the UriBuilder or ColorBuilder. There are two types of custom editors: IXmlEditors, which are inline editors that replace the default TextBox, and IXmlBuidlers, which are popup dialogs like the OpenFileDialog or ColorDialog. The type of editor is derived from the schema type information — "xs:date", "xs:time", "xs:datetime" results in the DateTimeEditor, and "xs:anyURI" results

in the UriBuilder. You can also annotate the schema with a custom "vs:builder" attribute in the "http://schemas.microsoft.com/Visual-Studio-IntelliSense" namespace. See the Help content for more information.

Infinite Undo/Redo To implement undo/redo I followed a common design pattern of Command objects with Undo and Redo methods. The UndoManager collects these in a list. Then the state of the UndoManager controls the enabled/disabled state of the Undo/Redo MenuItems. When the user selects the Undo menu item, the Undo method is called on the active command, and that command is pushed onto the Redo stack.

Figure 6. Undo/Redo in tree view Some operations in the editor cause many edits in the tree including the replace-all operation and editing the value of a namespace attribute. (When you change the value of a namespace attribute. every XmlNode bound to that namespace needs to be reconstructed with a new namespace URI, which can obviously affect a lot of nodes in the tree!) So, to make these operations one atomic undo operation, there is a CompoundCommand object that contains a list of smaller edit commands, and this CompoundCommand is put into the UndoManager. Other simpler command objects include the following, which all operate on XmlTreeNode and XmlNode objects:

Figure 7. Command objects in tree view The PasteCommand is special because it takes random XML text off the clipboard and parses it in context of the currently selected element in the tree, inheriting the namespaces in scope. The helper class TreeData uses the special XmlTextReader constructor that takes an XmlParserContext as input.

Unit Testing I had to do a good job of testing the new XML Notepad, and I was looking for an excuse to use the new Visual Studio 2005 UnitTest projects. The UnitTest runs from the TestManager under the new Test menu from within Visual Studio, launching XML Notepad and executing the 15 test methods I've written.

Figure 8. UnitTests When the test completes, you can then right-click on the Test Results window and select "Code Coverage Results". This brings up a summary of how many blocks were covered in each function. You can double-click the row in the list to bring up a color-coded source code view showing exactly which code has been covered. This made it really easy for me to get the code coverage up to about 85 percent. The only trick is that you don't get code coverage when you run the tests under the debugger, and the UnitTest project creates a file next to your solution called "localtestrun.testrunconfig" and "XmlNotepad.vsmdi," which you should not lose. If you do, then code coverage also will not work. Other than that, I have to say this new UnitTest stuff is one of the coolest new features in Visual Studio 2005.

Conclusion I hope you enjoy the all new XML Notepad. Feedback and suggestions are welcome, so just send e-mail to [email protected]. © 2017 Microsoft

XML Notepad 2007 Design - GitHub

XML Notepad 2007 Design ... Validation, IntelliSense, and Custom Editors ... you'll find the core XmlNotepad dll project, an Application project that builds.

668KB Sizes 16 Downloads 230 Views

Recommend Documents

Finale NotePad 2007 - [Trumpet Voluntary (D Major ...
œŸ œ œ œ œ œœ .œ. J œ œœ œœœœ œ œœ œœ œ œœœ œœ œ œ œ œ‰œ œœ ? ? ##. ## .. .. Vc. 1. Vc. 2. ˙ .œŸ œ œ œ œ œœ .œ. J œ œœ œœœœ.

notepad coding.pdf
For example, shutdown.bat. 6. Click on your file and it will automatically shutdown your Windows. image: http://cdn.techgyd.com/3rd-Notepad-Trick.png. You can ...

Notepad
had no public employment; he had never been entered at any of the. Inns of Court, either at the .... shell, lighted and warmed by gas, which sufficed for both these purposes. ... stood an electric clock, precisely like that in Mr. Fogg's bedchamber,

Notepad
In every place of great resort the monster was the fashion. They sang of ... spilled seas of ink during this memorable campaign, some even drawing blood; for from .... ten times more powerful; launch it at the rate of twenty miles an hour, and you ..

Enhanced Search Widget XML Configuration Version 3.7.4 - GitHub
What this does is gets all the valid coded value domain values and adds then to a ...... Please refer to the Enhanced Search Widget Fixed Datagrid Setup.pdf for ...

Notepad
From New York to London, by steamer and rail, 9 days. Total: 80 days". "Yes, in eighty days! ..... He took up his notebook, which contained the following ...

Notepad++.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Notepad++.pdf.

DIACC Design Challenge - GitHub
Pain Point 1: If an authorized user loses the original PDF certificate (along with the certificate number and access code) they cannot ... Designing for Opportunity (1 of 3). 4. Challenge .... verified as authentic against the blockchain using the mo

Notepad++ Cheat Sheet.pdf
Ctrl-G Launch GoToLine. Dialog. Ctrl-Q Single line comment. Ctrl-Shift-Q Single line uncomment. Ctrl-K Toggle single line. comment. Ctrl-Shift-K Block comment. Tab (selection of one or. more full lines). Insert Tabulation or. Space (Indent). Shift-Ta

Building Blocks Design - GitHub
daily-ipad-app-blocksworld-hd-lets-you-build-and-play-with-3d-b/. [4] Maister ... zombies-run-naomi-alderman-app. [6] Ohan ... columbia.edu/~ohan/oda08.pdf.

Notepad++ Cheat Sheet.pdf
Page 1 of 2. https://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Keyboard_And_Mouse_Shortcuts Notepad++ 6.6.3 2014-05-22. File menu.

Notepad++ Cheat Sheet.pdf
just how and why the project came to be is just now com- ing to light. Behind the red-brick facade of the Wharton Executive. Education .... Ctrl-Alt-Shift-O Send via Outlook ? menu. Shortcut. ↓ Action. ↓. F1 About. Shift+F1 Help Contents .... Not

advdos-Duncan.txt - Notepad
Seattle Computer Products for the right to sell Paterson's 86-DOS. (At that time ..... Familiar examples of external commands are CHKDSK, BACKUP, and RESTORE. ..... group of function calls automatically use this area as a data buffer. This.

XML Schema - Computer Science E-259: XML with Java
Dec 3, 2007 - ..... An all group is used to indicate that all elements should appear, in any ...

My First XML Parser
Oct 15, 2007 - Computer Science E-259: XML with Java, Java Servlet, and JSP .... phones didn't exist in 1636, so the course hadn't a phone number on file for.

The Algorithm Design Manual - GitHub
design form one of the core practical technologies of computer science. .... placed. Degree of difficulty ratings (from 1 to 10) have been assigned to all ... Updating a book dedication after ten years focuses attention on the effects of time. ......

Emergent Architecture Design (draft) - GitHub
May 15, 2014 - the majority of the smartphone market is Android and iOS, approximately 90% of the market[1], we decided to start by implementing our game ...

Digital Design with Chisel - GitHub
Dec 27, 2017 - This lecture notes (to become a book) are an introduction into hardware design with the focus on using the hardware construction language Chisel. The approach of this book is to present small to medium sized typical hardware components

Comparison of 2003, 2004, 2007, 2010 and 2013 Releases - GitHub
Denial of Service. ✘. A9[2]. ✘. ✘. ✘ ... Broken Authentication and Session Management. A3. A3. A7 ... [6] Renamed “Web and Application Server ” from T10 2003.

Design module user manual - GitHub
In the design module objects like buildings can be selected. For each case, measures ... Figure 3, parts of the web application for control and visualizing data. 1.

XML programming with SQL/XML and XQuery
agers fulfill vital responsibilities in complex informa- tion systems by ... other information-service systems. Permission to ...... Client, network, and server resources ...

XML programming with SQL/XML and XQuery - IEEE Xplore
XML programming model evolution. SAX (the simple API [application programming in- terface] for XML)1 was the first popular interface for. XML programming.