0

I understand that this question can a generic one, I want to parse the below xml structure.I am interested only in the testcase tag's attribute name and time and if it has failure child its message attribute .I am able to do it seperately i.e all testcase name and time in one shot,and similarly all failure message seperately.But i am never able to keep printing name and time followed by any failure message if any consecutively.

<?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&#x0A;Value of: Factorial(-1)&#x0A;  Actual: -1&#x0A;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&#x0A;Value of: Factorial(1)&#x0A;  Actual: 1&#x0A;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&#x0A;Value of: Factorial(2)&#x0A;  Actual: 2&#x0A;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>

To be more specific I tried the following

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);
                    }

So basically my doubt is ,As here i am able to get the result in seperate chunk,can i somehow merge it.

shivi
  • 147
  • 2
  • 12
  • 1
    http://stackoverflow.com/help/how-to-ask – Pete Garafano Mar 28 '14 at 00:04
  • yes, this is too broad for one question. It sounds like you are aware of some of the steps you need to take. Why not pick one, much smaller step, give it a try, and then ask for corrections on just that. – Mike M Mar 28 '14 at 02:00

1 Answers1

1

I would generate classes using xsd tool from this schema or xml file directly.

hazzik
  • 13,019
  • 9
  • 47
  • 86