Xpath axes explained

September 15th, 2014

The original article at http://our.umbraco.org/wiki/reference/xslt/xpath-axes-and-their-shortcuts explains it best.

If the original article goes missing I have copied it below.

All kudos goes to the original author, not me.

XPath works on the premise of Axes, which is how the data relates to the current node.  There are several Axes listed below with graphic depictions of the results.

The following picture from Crane Softwrights demonstrates the axes graphically.

Note: The following are v4.5+ XPaths

The following XPath examples are using the “new” XML Schema introduced in Umbraco v. 4.5 – In Umbraco versions before 4.5, the XML node for a document was simply named <node>, so if you need to select nodes in and older installation, replace *[@isDoc] in the following with “node” and everything should just work.

Self Axis

While it is rarely used, the self axis actually returns the node in reference.


Child Axis

We mentioned the child axis earlier, and actually used its shortcut right off.  The child axis select the nodes immediately below the node in reference.  While the verbose method is rarely used, it is here for reference.


Parent Axis

The parent axis allows us to see the node immediately above the node in reference.


Descendant Axis

Next we have descendant.  The descendant axis retrieves all nodes below the node in reference no matter the depth.


Descendant-or-self Axis

The descendant-or-self axis returns all nodes below the current node, but also returns the node in reference to the command.


Ancestor Axis

The ancestor axis selects all nodes that are ancestors, or the parent, and the parent’s parent, and so on, to the node in reference.


Ancestor-or-self Axis

The ancestor-or-self axis selects all nodes that are ancestors, or the parent, and the parent’s parent, and so on, including the node in reference.


Preceding Axis

The preceding axis selects all nodes no matter the depth, that are located on parent-level and who are also located before (preceding) its parent of the node in reference.


Preceding-sibling Axis

The preceding axis selects all nodes that are located on the same level who are also located before (preceding) the node in reference.


Following Axis

The preceding axis selects all nodes no matter the depth, that are located on parent-level and who are also located after (following) its parent of the node in reference.


Following-sibling Axis

The preceding axis selects all nodes that are located on the same level who are located after (following) the node in reference.



What the Hyper-V menus mean

September 15th, 2014

The Microsoft Hyper-V user interface is quite good but the menus are not self explaining when it comes to branching and making snapshots.

Thankfully someone has written down an explanation.


Note that when you have branched once (or was it taken a snapshot) something happens that makes another feature fail. (I can’t remember which though)

If the original article disappears I have copied it down below.

All gratitude should go to the original author. http://www.virtualizationadmin.com/authors/janique-carbone/

Creating a Snapshot

Figure 1 shows the Hyper-V Manager console with a single running VM before the creation of the first snapshot. In order to create a snapshot, you just highlight the VM, then right-click and select the Snapshot menu option.

Figure 1: Creating a snapshot in Hyper-V Manager

The Hyper-V Manager Snapshots pane displays a tree structure to represents the VM snapshot hierarchy, as shown in Figure 2. The root node of the tree is the first snapshot that was created. Under the root node, there is a child named Now which represents the running version of the VM. By default, snapshots are labeled using the VM name concatenated with the creation timestamp. In order to rename the snapshot, highlight it, then right-click and select Rename from the menu.

Figure 2: Hyper-V Manager Snapshot Pane Display

Within a snapshot hierarchy, with each new snapshot that is taken, the active AVHD is detached from the VM, and becomes the parent of a new child AVHD that is attached to the VM and captures changes to the VM data until the next snapshot is created.

For more details on the snapshot creation process, you can refer to my previous article, “Understanding and Using Microsoft Windows Server 2008 Hyper-V Snapshots”, and video, “Using Hyper-V Snapshots”.

Using the Revert Option

Using the Revert option allows you to return the VM to the state of the last snapshot that was taken. For example, in Figure 3, you can see that three snapshots were captured for the Win2008 VM. Each snapshot was renamed to indicate the order and state of the VM when the snapshot was taken. The VM was running during Snapshot 1 and Snapshot 2, but powered-off for Snapshot 3, and then restarted when Snapshot 3 was completed. The last object in the hierarchy, marked by Now, indicates the running VM.

Figure 3: Hyper-V Manager Snapshot Hierarchy

If the Revert option is selected, the configuration and state of the VM are returned to the settings saved in Snapshot 3, since it is the last snapshot that was taken. During the Revert process, the VM is stopped, the current AVHD is deleted, and a new AVHD is created. The VM configuration saved during the snapshot is restored and the name of the new AVHD is updated in the VM configuration file. Because the virtual machine was powered-off when Snapshot 3 was taken, there are no save state files to load and the virtual machine remains powered-off, as shown in Figure 4. It is important to stress that when a Revert is performed, all configuration modifications made to the running VM since the snapshot was taken are discarded. However, you can make changes to the memory, processor, virtual hard disk adapter, or any other VM hardware setting, when the Revert has completed.

Figure 4: Hyper-V Manager View after Revert to Snapshot 3

Another thing to note in Figure 4 is that the snapshot hierarchy view did not change after the Revert was performed. That is expected since none of the snapshots are altered during this operation. However, using the Revert option again will continue to return the VM to the configuration and state of the last snapshot taken. In this sense, the snapshot Revert feature can be thought of as a single-level undo feature. It cannot be used repeatedly to traverse up the snapshot hierarchy. In the current example, if the VM must be returned to the configuration and state of Snapshot 1 or Snapshot 2, the Apply option must be used.

Using the Apply Option

As shown in Figure 5, to return to a snapshot that is higher than one level up from the running VM (represented by the Now marker in the Snapshot pane), you must highlight the snapshot, right-click, and choose the Apply option from the menu. If you did not create a snapshot of the running virtual machine, you are prompted to do so prior to the Apply operation, or you can choose to continue and apply the selected snapshot without saving the current configuration and state. Just as in the case of the Revert option, if you do not take a snapshot prior to the Apply operation, the running virtual machine configuration and state will be lost.

Figure 5: Using the Snapshot Apply Option in Hyper-V Manager

The snapshot Apply process is similar to the Revert process. The virtual machine is stopped, the active AVHD is deleted, and a new AVHD is created. The snapshot virtual machine configuration is restored and the name of the new AVHD is updated in the VM configuration file. As shown in Figure 6, the virtual machine is then restarted, and the save state files (.vsv and .bin) are loaded.

Figure 6: Hyper-V Manager Snapshot Hierarchy after Apply of Snapshot 2

You can also see in Figure 6 that the Now marker moved right under Snapshot 2 to indicate that the running VM is based on Snapshot 2. At this point, if a new snapshot is created, it is placed in the Snapshot 2 hierarchy. After the Apply is performed, Snapshot 2 essentially represents a subtree in the snapshot hierarchy, as shown in Figure 7.

Figure 7: Hyper-V Manager Snapshot Hierarchy with the Snapshot 2 Subtree

Using the Snapshot Delete Option

If you decide that you no longer need a snapshot or snapshot subtree, Hyper-V provides two different Delete options to permanently remove one or more snapshots from the snapshot hierarchy, as shown in Figure 8.

Figure 8: Hyper-V Manager Delete Snapshot and Delete Snapshot Subtree Options

Deleting a single snapshot will not affect other snapshots, but it will immediately delete the configuration file and save state files associated with the snapshot. In a snapshot hierarchy, the snapshot AVHD is related to other snapshot AVHDs through a parent-child relationship. Therefore, a snapshot AVHD is only immediately deleted if it is not the parent of a child AVHD. If there is only one child AVHD, it is merged into the parent AVHD the next time that the VM is powered-off. If a parent AVHD has multiple children, then it is retained until only one of the child AVHD remains. The child AVHD is then merged into the parent AVHD the next time that the VM is powered-off.

Deleting a snapshot subtree immediately deletes the configuration and save state files associated with all the snapshots in the subtree. If the running virtual machine AVHD is not a child of any snapshot in the subtree, then all of the AVHDs in the subtree will also be deleted. If the running virtual machine AVHD depends on a chain of AVHDs in the subtree that is deleted, then the AVHD chain will be merged into the AVHD that is one level above the deleted subtree, the next time that the VM is powered-off.


Dotnet, Sysinternals DebugView, Debug.WriteLine and IIS

September 6th, 2014

I finally managed to write through Debug.WriteLine to Sysinternals DebugView through reading this article. Kudos to the author.

If the original article disappears; here is the recipe in short:

Start Sysinternals Debugview as administrator. Make sure Capture global win32 is checked.
Make sure Visual studio is not attached as debugger because when you run the VS debugger it hogs all information. (In VS you can find the output in the Output window with Show output from Debug.)

Besides Debug.WriteLine also play around with Trace.WriteLine and Console.WriteLine.

Unit tests and comparing long strings or objects

June 16th, 2014

I have tested and really liked ApprovalTests with more info in the blog by Llewellyn Falco.

When the unit test fails, and only if it fails, a comparer of choice pops up (think Winmerge or similar).

Say you have a long string where, somewhere, the testing framework reports a diff; you have to sift through the whole 1000 characters and compare by eye. If the discrepancy is a space/tab or apostrof/accent you might have a very hard time to spot the diff.
Or say you have an object with 10 or so properties. The unit testing framework reports a diff and you have to iterate through the properties and maybe sub properties for two objects. Tedious and not fun even the first time. The third of 10th time you really should be looking for a better solution.

I started writing my own but dropped that project in a second for AprovalTests.

Another, not as polished, solution is from SHaack. It is an extension to a unit test framework. You have to implement your own if you have another unit testing framework of choice.

Forefront threat management gateway 2010 – the page cannot be displayed

June 10th, 2014

Error code: 500 Internal server error. The system cannot find the file specified. (2)

This error might be because of your OWA password is about to expire and there is a fault somewhere in the Exchange/OWA installation.

Screen dump of TMG reporting 500 dues to password is about to expire.

Threat management gateway 2010 with 500 error due to password is about to expire.

The remedy is to change your password which you can do at the OWA login page. There is a check box “I want to chang emy password after logging on” to use.

OWA login page

OWA login page

tags: , | categories: Miscellaneous | no comments »

Why using the disc icon as saving icon is considered good

June 10th, 2014

Regardless whether skeumorphism is good or not; a diskette icon for saving is passé.
But there is no better.

We could use a mobile phone as icon for saving as we use a mobile phone for that. And anything else.
We could have a mobile phone as icon for everything. It would be easier to remember just one icon. It would save band width as it could be cached. Support calls would be easier as we could just answer “press the button with the mobile phone icon”.


Diskette icon with CC0 license

Diskette icon, CC0 license (http://creativecommons.org/publicdomain/zero/1.0/deed.en) (fromhttp://pixabay.com/en/floppy-disk-symbol-signs-symbols-24172/)

Indoor gardening and composting

June 6th, 2014


The art of gardening without soil. Makes my geek heart vibrate.

Here is an example of how to create a solution with Ikea stuff. There are both more complex and simpler ways to accomplish this.


Instead of simple composting; first ferment and get some juice out – then compost.

With a bucket under the kitchen sink one can play with the food that wasn’t eaten. Here is a Swedish site for the stuff.

Why I don’t recommend my customers to rely on Visual studio for development.

June 5th, 2014


The only way to edit architecture and modelling with Visual studio is to buy the very expensive Ultimate edition. This means that it will be not everyone can be involved in the process of evolving the solution.


Development requires Architecting an Architecture in some way or another. This architecture is not written in stone but changes as time or business changes; we call it requirements change.

In the old days, like 20 years ago, I learned that there is an architecture phase and then a development phase. This is not considered best practice any more. Also not best practice is to have silos with Architectures and Testers and Coders and Database managers.

This is where Microsoft and Visual studio fails. Not technically but license wise.

Look at this part of a comparison chart for different Visual studio versions. It clearly explains that Architects must have the Ultimate edition and that no one but Architects are allowed to change any Architect document. (the Ultimate edition is way more expensive than the others)

Visual studio architecture blunder

Visual studio comparison fail where it shows that only Ultimate can edit architecture stuff. Original from Wikipedia.

ReAttach is a Visual studio plugin to reattach the debugger

May 9th, 2014

I have earlier, here and here, written about how to write a macro to attach the debugger to a running process as it is often faster than starting the process anew.

Lately the Visual studio plugin ReAttach has come on my radar and I have tried it with success. It remembers the last attaches you did and keeps them in a menu. Fewer key strokes and fast attaching is the result.

How I write Equals and GetHashCode in csharp

April 25th, 2014

My code is copied with pride from the net.

        /// <summary>This is standard overridden Equals method.
        /// Code is copied with pride from
        /// http://msdn.microsoft.com/en-us/library/336aedhh(v=vs.85).aspx
        /// </summary>
        /// <param name="obj"/>
        /// <returns></returns>    
        public override bool Equals(object obj)
            if (null == obj || GetType() != obj.GetType())
                return false;
            var b = (MyType)obj;
                this.Property1 == b.Property1 &&
                this.PropertyN == b.PropertyN;

        /// <summary>This is the ordinary overriden GetHashCode
        /// with code proudly copied from
        /// http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
            unchecked // Overflow is fine, just wrap
                const int Salt = 23;
                var hash = 17;
                hash = hash + Salt * Property1.GetHashCode();
                hash = hash + Salt * PropertyN.GetHashCode();
                return hash;