0
我明白這個問題可以通用一個,我想解析下面的XML結構。我只對testcase標記的屬性名稱和時間感興趣,並且它的子消息屬性失敗。我能夠單獨做到這一點,即所有測試用例的名稱和時間在一個鏡頭中,並且類似地所有失敗信息是分開的。但是我永遠不能夠繼續打印名稱和時間,如果連續出現任何失敗信息。C#中的Report.xml解析
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="4" failures="2" disabled="0" errors="0" timestamp="2014-03-27T07:58:04" time="0.168" name="AllTests">
<testsuite name="FactorialTest" tests="3" failures="2" disabled="0" errors="0" time="0.139">
<testcase name="Negative" status="run" time="0.047" classname="FactorialTest">
<failure message="c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:13
Value of: Factorial(-1)
 Actual: -1
Expected: -10" type=""><![CDATA[c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:13
Value of: Factorial(-1)
Actual: -1
Expected: -10]]></failure>
</testcase>
<testcase name="Zero" status="run" time="0.001" classname="FactorialTest" />
<testcase name="Positive" status="run" time="0.071" classname="FactorialTest">
<failure message="c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:24
Value of: Factorial(1)
 Actual: 1
Expected: 11" type=""><![CDATA[c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:24
Value of: Factorial(1)
Actual: 1
Expected: 11]]></failure>
<failure message="c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:25
Value of: Factorial(2)
 Actual: 2
Expected: 22" type=""><![CDATA[c:\users\win_7_32_sp1\documents\visual studio 2012\projects\simplemath\unit_test_simplemath\unit_test_simplemath.cpp:25
Value of: Factorial(2)
Actual: 2
Expected: 22]]></failure>
</testcase>
</testsuite>
<testsuite name="TestSuiteName" tests="1" failures="0" disabled="0" errors="0" time="0.004">
<testcase name="Suite2" status="run" time="0" classname="TestSuiteName" />
</testsuite>
</testsuites>
更具體我嘗試以下
Report.WriteLine("TestSuiteName--FunctionName: \n");
XDocument docs = XDocument.Load(ConfigLocation);
var rows = docs.Descendants("testcase").Select(x => string.Format(@"{0}-{1}--->ExecutionTime: {2}Seconds", x.Attribute("classname").Value, x.Attribute("name").Value, x.Attribute("time").Value));
foreach (string row in rows)
{
Report.WriteLine(row);
}
Report.WriteLine(Environment.NewLine);
Report.WriteLine("Failure cases: ");
XmlNodeList nodes1 = doc.GetElementsByTagName("testcase");
foreach (XmlNode node in nodes1)
{
if(node.HasChildNodes)
Report.WriteLine(node.FirstChild.Attributes[0].Value);
}
所以基本上我的疑問是,正如我在這裏能夠得到的結果在單獨的塊,我可以採用某種合併。
http://stackoverflow.com/help/how-to-ask –
是的,這對於一個問題來說太寬泛了。這聽起來像你知道你需要採取的一些步驟。爲什麼不選擇一個更小的步驟,嘗試一下,然後要求更正這一點。 –