问题描述
我以编程方式使用VS2010和Fxcop 10.0(fxcopcmd.exe)来生成fxcop分析结果(xml文件)
I use VS2010 and Fxcop 10.0 (fxcopcmd.exe) programatically for generate fxcop analysis results (xml file)
我想要解析xml文件以获取fxcop分析结果.
I would like parser xml file for fxcop analysis results.
在Java语言中,我发现了这一点: http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson.plugins/violations/0.7.7/hudson/plugins/violations/types/fxcop/FxCopParser .java
In java language I've found this:http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson.plugins/violations/0.7.7/hudson/plugins/violations/types/fxcop/FxCopParser.java
关于解析器C#的任何建议?
any suggestions for parser C#?
推荐答案
我使用此代码获取报告中的问题数量.您也可以从XElement检索实际消息
I use this code to get number of issues in the report.You can retrieve actual messages from XElement as well
public class Parser
{
public Parser(string fileName)
{
XDocument doc = XDocument.Load(fileName);
var issues = GetAllIssues(doc);
NumberOfIssues = issues.Count;
var criticalErrors = GetCriticalErrors(issues);
var errors = GetErrors(issues);
var criticalWarnings = GetCriticalWarnings(issues);
var warnings = GetWarnings(issues);
NumberOfCriticalErrors = criticalErrors.Count;
NumberOfErrors = errors.Count;
NumberOfCriticalWarnings = criticalWarnings.Count;
NumberOfWarnings = warnings.Count;
}
public int NumberOfIssues
{
get;
private set;
}
public int NumberOfCriticalErrors
{
get;
private set;
}
public int NumberOfErrors
{
get;
private set;
}
public int NumberOfCriticalWarnings
{
get;
private set;
}
public int NumberOfWarnings
{
get;
private set;
}
private List<XElement> GetAllIssues(XDocument doc)
{
IEnumerable<XElement> issues =
from el in doc.Descendants("Issue")
select el;
return issues.ToList();
}
private List<XElement> GetCriticalErrors(List<XElement> issues)
{
IEnumerable<XElement> errors =
from el in issues
where (string)el.Attribute("Level") == "CriticalError"
select el;
return errors.ToList();
}
private List<XElement> GetErrors(List<XElement> issues)
{
IEnumerable<XElement> errors =
from el in issues
where (string)el.Attribute("Level") == "Error"
select el;
return errors.ToList();
}
private List<XElement> GetCriticalWarnings(List<XElement> issues)
{
IEnumerable<XElement> warn =
from el in issues
where (string)el.Attribute("Level") == "CriticalWarning"
select el;
return warn.ToList();
}
private List<XElement> GetWarnings(List<XElement> issues)
{
IEnumerable<XElement> warn =
from el in issues
where (string)el.Attribute("Level") == "Warning"
select el;
return warn.ToList();
}
}
这篇关于C#中的解析器FxCop结果Xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!