VSoft Technologies Blogs

rss

VSoft Technologies Blogs - posts about our products and software development.

(It's been a while since I blogged about anything, so I thought I'd write about this while my coffee kicks in on a Monday morning.)

An issue which comes up quite often is people seeing this error when they try to use XML actions in FinalBuilder or Automise:

XPath returned no node : /Project/Import

The reason is because of the way MSXML deals with document namespaces.  If your XML file uses XML namespaces (and most do), then you need to tweak the action slightly.

I'm not going to go into XML Namespaces in detail. There are better places to learn about them. I'll just show you an example:

Example

Say you have a Visual Studio 2005 .csproj file (which is really just an XML file wearing a funny hat.) You want to iterate over all of the imported project names with an XML Node Iterator action. If you try to use the XPath /Project/Import, then you'll see the error I showed above.

Here's the first line of the .csproj file:

This means the document has a default XML Namespace, which is "https://schemas.microsoft.com/blahblahblah". This is why MSXML can't follow the XPath properly.

To fix this, open the XML action and navigate to the "MSXML Parser" page.

MSXML Parser Dialog

Turn on the "Automatically use namespace prefixes..." checkbox, and type a letter in the field for the default Namespace. I used "x" in the screenshot shown above.

Now change your XPath from /Project/Import to:

/x:Project/x:Import

It works! Namespace prefix "x" now refers to the default namespace in the document.

Pedantic Details

  • There is a way to specify the namespace URI as part of the XPath, without using this prefix feature, but the resulting XPaths are enormous and hard for humans to read.
  • If you have namespace prefixes defined as attributes in the document root node, ie s:xmlns="https://www.myfunkyurl.com/namespace", then turning on this option will let you use the prefixes in your XPath.
  • This is the best solution we've come up with so far. We're planning to revisit this in future and (hopefully) make it all automatic without any manual configuration or custom prefixes.

 

Showing 4 Comments

Avatar
Physical Condition 16 years ago

nice post


Avatar
tlaw713 16 years ago

Hi guys,<br><br>Any updates on this one? <br><br>TIA,<br>Tracey


Avatar
angus 17 years ago

Erhan, Thanks for pointing this out. I have an FB 5 test build which generates XPaths with namespace prefixes. Email support at finalbuilder dot com if you'd like the download URL. It will also be in the next FB 6 beta build. Regards, Angus


Avatar
E.Tamer 17 years ago

Hi Angus,<br><br>ok that does work. But there is a problem, if i have to iterate through all special nodes, and do assign the xpath value to a variable, to be able to get an attribute-value of the variable.<br><br>Do you have experience in this?<br><br>Regards<br><br>Erhan



Comments are closed.