有关读取xml文件的问题

zjy1985cool 2008-12-24 10:34:13
<?xml version="1.0" encoding="utf-8" ?>
<WTT-Logger>
<RTI ID="3805221601" Machine="AUTO8" ProcessName="E:\WTT\JobsWorkingDir\Tasks\WTTJobRunCB1B693C-72C2-DD11-9E99-00188B40CEEE\MSTestRun.exe" ProcessID="5488" ThreadID="256" BaseTime="2008:12:5 2:24:54:812" Frequency="2593530000" />
<CTX ID="384048256" Current="WTTLOG" Parent="ROOT" />
<Machine
Build="2600.00"
Platform="x86"
OS="Microsoft Windows XP"
ServicePack="Service Pack 3"
Version="5.1"
BuildLab="xpsp"
BuildDate="080413-2111"
Language="English (US) (REDMOND)"
Config="n/a" CA="849104802" LA="850253450" >
<rti id="3805221601" />
<ctx id="384048256" />
</Machine>
<CTX ID="3065565191" Current="CommandLineTest" Parent="WTTLOG" />
<StartTest
Title="CommandLineTest"
TUID="" CA="905185288" LA="905504076" >
<rti id="3805221601" />
<ctx id="3065565191" />
</StartTest>
<EndTest
Title="CommandLineTest"
TUID=""
Result="Fail"
Repro="" CA="909962792" LA="910146700" >
<rti id="3805221601" >2</rti>
<ctx id="3065565191" />
</EndTest>
<CTX ID="3864055732" Current="GetMessageName1ArgTest" Parent="WTTLOG" />
<StartTest
Title="GetMessageName1ArgTest"
TUID="" CA="911331904" LA="911622792" >
<rti id="3805221601" />
<ctx id="3864055732" />
</StartTest>
<EndTest
Title="GetMessageName1ArgTest"
TUID=""
Result="Pass"
Repro="" CA="911429452" LA="911927600" >
<rti id="3805221601">pass</rti>
<ctx id="3864055732">pass</ctx>
</EndTest>
<Msg
UserText="Review" CA="1017570936" LA="1017809328" >
<rti id="3805221601" />
<ctx id="384048256" />
</Msg>
<PFRollup
Total="65"
Passed="10"
Failed="55"
Blocked="0"
Warned="0"
Skipped="0" CA="1020003000" LA="1020367408" >
<rti id="3805221601" />
<ctx id="384048256" />
</PFRollup>
</WTT-Logger>

我想要获得的是
<EndTest
Title="GetMessageName1ArgTest"
Result="Pass" >
</EndTest>
同时 result="fail"
...全文
92 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjy1985cool 2008-12-24
  • 打赏
  • 举报
回复
我是菜鸟 能写全点吗?
private void button1_Click(object sender, EventArgs e)
{


OpenFileDialog P_OpenFile = new OpenFileDialog();
P_OpenFile.Multiselect=true;
if (P_OpenFile.ShowDialog() == DialogResult.OK)
{
string[] MultiFiles = P_OpenFile.FileNames;
foreach(string muFile in MultiFiles)
{
//txtXml.AppendText(muFile);
textBox2.Text = muFile;
}
//LBoxURL.Items.Add(MultiFiles);
}

}
#endregion

private void button2_Click(object sender, EventArgs e)
{
string xpath = String.Format("/WTT-Logger/EndTest[@title='{0}' and @Result='{1}']", "GetMessageName1ArgTest", "Fail");
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

doc.Load(textBox2.Text);
XmlNode node = doc.SelectSingleNode(xpath);

if (node != null)
{
textBox1.AppendText(node.Value);
}
}
lovefootball 2008-12-24
  • 打赏
  • 举报
回复
title
-->
Title
lovefootball 2008-12-24
  • 打赏
  • 举报
回复
string xpath = String.Format("/WTT-Logger/EndTest[@title='{0}' and @Result='{1}']","GetMessageName1ArgTest","Fail");
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(你的文件);
XmlNode node = doc.SelectSingleNode(xpath);

if (node != null)
{
//todo
}
zlb789 2008-12-24
  • 打赏
  • 举报
回复

string XPath = "/WTT-Logger/EndTest[@title='?']";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

doc.Load((HttpContext.Current.Server.MapPath(filepath)));
System.Xml.XmlNode node = doc.SelectSingleNode((XPath.Replace("?", "GetMessageName1ArgTest")));
//这里的node就是要的
//下面是属性
node.Attributes["result"].InnerText;

当然还可以通过遍历根节点的子接点 然后判断是不是你要的那个节点

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧