tags:

views:

77

answers:

2

I'm trying to extract the coverage data from XML file generated by NCover using C#. The XML file looks something like this:

<namespace n="namespace" t="11" fp="11" u="0" c="100">
<class n="foo" t="11" fp="11" u="0" c="100">
      <method n="foo1" t="1" fp="1" u="0" c="100" l="16" />
      <method n="foo2" t="1" fp="1" u="0" c="100" l="13" />
</class>

Right now I'm using pattern matching for when there's a value > 0 for c and then looking behind to retrieve the method name, but its really cumbersome. Is there a better way to do this?

A: 

Do you mean that you're not using a standard XML API (SAX, DOM, or other) to process the file? That's brave... well, dangerous, really.

Using XPath, it would be pretty simple to find the elements where c>0. Here's an (untested) expression that should do the trick:

/class/method[@c>0]
Dan Breslau
A: 

What version of NCover are you trying to parse?

NCover 3 has a report format that has the numbers rolled up for you.

Joe Feser

NCover

joe.feser