我有以下 XML 文件:
<testsuite name="Tests" rxversion="5.4.5.19886" id="d1203701-d61c-4ae6-932d-faa44beb925a" reportfilename="%S_%Y%M%D_%T.rxlog" reporttemplatefolder="" reportxslfilename="" placescreenshotsinfolder="True" ReportTime="RelativeToTestSuiteStartTime" reportwriteinterval="30000ms" reportcompress="False" enabletracingscreenshots="True" TracingScreenshotMode="Foreground" TracingScreenshotQuality="40" reportlevel="Info;20" warnunboundvariables="False">
<testconfigurations default="TestRun">
<testconfiguration name="TestRun" />
</testconfigurations>
</testsuite>
以下代码用于更新 XML:
var xe = new XmlDocument();
xe.Load("Z:\\Tests\\Tests.rxtst");
string testconfig = "//testsuite/testconfigurations/testconfiguration";
string testconfigend = "//testsuite";
XmlNode tc = xe.SelectSingleNode(testconfig);
XmlNode tcend = xe.SelectSingleNode(testconfigend);
XmlElement xs = xe.CreateElement("testcase");
xs.SetAttribute("id", "450c9a87-75dc-4538-bc2c-6df6eb359d2a");
XmlNode par = tc.ParentNode;
par.InsertBefore(xs, tc.LastChild);
xe.Save("st.rxtst");
使用此代码,我得到以下 xml 输出:
<testsuite name="Tests" rxversion="5.4.5.19886" id="d1203701-d61c-4ae6-932d-faa44beb925a" reportfilename="%S_%Y%M%D_%T.rxlog" reporttemplatefolder="" reportxslfilename="" placescreenshotsinfolder="True" ReportTime="RelativeToTestSuiteStartTime" reportwriteinterval="30000ms" reportcompress="False" enabletracingscreenshots="True" TracingScreenshotMode="Foreground" TracingScreenshotQuality="40" reportlevel="Info;20" warnunboundvariables="False">
<testconfigurations default="TestRun">
<testconfiguration name="TestRun" />
<testcase id="450c9a87-75dc-4538-bc2c-6df6eb359d2a" />
</testconfigurations>
</testsuite>
我想将testcase
元素添加为testconfiguration
. 输出应该是这样的:
<testsuite name="Tests" rxversion="5.4.5.19886" id="d1203701-d61c-4ae6-932d-faa44beb925a" reportfilename="%S_%Y%M%D_%T.rxlog" reporttemplatefolder="" reportxslfilename="" placescreenshotsinfolder="True" ReportTime="RelativeToTestSuiteStartTime" reportwriteinterval="30000ms" reportcompress="False" enabletracingscreenshots="True" TracingScreenshotMode="Foreground" TracingScreenshotQuality="40" reportlevel="Info;20" warnunboundvariables="False">
<testconfigurations default="TestRun">
<testconfiguration name="TestRun">
<testcase id="450c9a87-75dc-4538-bc2c-6df6eb359d2a"/>
</testconfiguration>
</testconfigurations>
</testsuite>
如何将testcase
元素添加为 的子元素testconfiguration
?
更新
现在id
已正确设置,但该元素未作为testconfiguration
节点的子元素添加。