日期:2014-05-18  浏览次数:20871 次

有关读取xml文件的问题
<?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"

------解决方案--------------------
C# code

 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;

------解决方案--------------------
string xp