XML Namespaces

 

A common issue that occurs when using the FinalBuilder XML actions is the following error:

 

XPath returned no node : /Project/Import

 

When using an XML document the uses namespaces, this error can occur even when the XPath to the node is correct. For example if you wanted to iterate over all the imported project names in a .csproj  and you defined the XPath to iterate over as /Project/Import then you would see the error above. If you view .csproj file in a text editor and look at the first line then you will see something resembling the following:

 

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

 

The xmlns attribute that indicates that this document has a default namespace. This is why MSXML will not be able to find the /Project/Import nodes given the /Project/Import XPath.

 

To allow MSXML to find these nodes, go to the MSXML parser page of the action (or the XML Document Define action that you are using) and enable the Automatically use the namespace prefixes declared in the document root node option. You need to provide a letter to prefix the default namespace, to do this enter a letter in the Identifier prefix for the default namespace field.

 

 

 

 

In the screenshot above, x has been used as the prefix for the default namespace. To reference the /Project/Import nodes the XPath used is x:/Project/x:Import as x is referencing the default namespace of the document.