How to use C# to transform the XML into another format

Oreybbry

New Member
I need to transform the xml into another format.The original xml is\[code\]<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://stackoverflow.com/questions/15617114/TestReport_Sum.xsl'?><Report> <TestProperties TestStartTime="3/25/2013 3:55:43 PM" TestFinishTime="3/25/2013 3:55:44 PM" TestDuration="00:00:01"> <MachineList TestMachineName="Local Server" TestMachineIP="10.35.49.121" /> <MachineList TestMachineName="Remote Server" TestMachineIP="10.35.12.251" /> </TestProperties> <Statistic TotalCase="3" CasePass="2" CaseFail="1" CaseTimeOut="0" CaseNotRun="0" CasePassRate="66.67" /> <ResultList> <TestCase CaseName="Case1" CaseStatus="Fail" CaseDuration="00:00:01"> <TestStep StepID="1" StepName="RunCommand" StepParam="cd" StepTarget="" StepStatus="Pass" Detail="" /> <TestStep StepID="2" StepName="RunCommand" StepParam="cd" StepTarget="10.35.12.251" StepStatus="Fail" Detail="Error: plink: the -pw option can only be used with the SSH protocol<br><br>" /> <TestStep StepID="3" StepName="RunCommand" StepParam="dir" StepTarget="" StepStatus="Pass" Detail="" /> <TestStep StepID="4" StepName="RunCommand" StepParam="dir" StepTarget="10.35.12.251" StepStatus="Fail" Detail="Error: plink: the -pw option can only be used with the SSH protocol<br><br>" /> <TestStep StepID="5" StepName="RunCommand" StepParam="dirs" StepTarget="" StepStatus="Fail" Detail="Error: This command was executed failed!<br>Error: 'dirs' is not recognized as an internal or external command,<br>operable program or batch file.<br><br>" /> <TestStep StepID="6" StepName="RunCommand" StepParam="dirs" StepTarget="10.35.12.251" StepStatus="Fail" Detail="Error: plink: the -pw option can only be used with the SSH protocol<br><br><br>" /> </TestCase> <TestCase CaseName="Case2" CaseStatus="Pass" CaseDuration="00:00:00"> <TestStep StepID="1" StepName="RunCommand" StepParam="cd" StepTarget="" StepStatus="Pass" Detail="" /> </TestCase> <TestCase CaseName="Case3" CaseStatus="Pass" CaseDuration="00:00:00"> <TestStep StepID="1" StepName="RunCommand" StepParam="dir" StepTarget="" StepStatus="Pass" Detail="" /> </TestCase> </ResultList></Report>\[/code\]And the expected output format is\[code\] <?xml version="1.0" encoding="utf-8"?> <testsuites tests="3" failures="1" disabled="0" errors="0" time="0" name="FunctionalTests"> <testsuite name="FT_Suite" tests="3" failures="1" disabled="0" errors="0" time="0"> <testcase name="Case1" status="Fail" time="0" classname="FT_Suite"> <failure type="Test Case Run Error"><a href="http://stackoverflow.com/questions/15617114/D:/TestAutomation/Report/Test.xml">Click to see error detail</a></failure> </testcase> <testcase name="Case2" status="Pass" time="0" classname="FT_Suite" /> <testcase name="Case3" status="Pass" time="0" classname="FT_Suite" /> </testsuite> </testsuites>\[/code\]The original XMl would be stored as a string which is stored in the memory.And the output xml would be writed as a XML file.Besides using c# code to load the xml and rewrite it with the new format, is there any other faster and easier method?Thanks
 
Back
Top