我無法讓我的Xpath查詢工作,儘管在紙上它應該是正確的。我甚至試圖讓無屬性的單節點,甚至無法得到這個...C#XML XPath查詢不起作用
我在做什麼錯?
var trxXml = new XmlDocument();
trxXml.Load(InputTrxFile);
XmlElement root = trxXml.DocumentElement;
var unitTestResult = trxXml.GetElementsByTagName("UnitTestResult");
foreach (XmlElement runinfo in unitTestResult)
{
// Find failed tests, works fine then...
string TestName = runinfo.GetAttribute("testName"); // works fine
// Want to find equivalent TestDefinitions/UnitTest
/* Tried
TestRun/TestDefinitions/UnitTest[@name='thetest']
/TestRun/TestDefinitions/UnitTest[@name='thetest']
TestDefinitions/UnitTest[@name='thetest']
/TestDefinitions/UnitTest[@name='thetest']
UnitTest[@name='thetest']
variations with no attribute test JUST to get a node
Example http://www.csharp-examples.net/xml-nodes-by-attribute-value/
*/
var xpath = string.Format(@"/TestRun/TestDefinitions/UnitTest[@name='{0}']", TestName);
XmlNode node = trxXml.SelectSingleNode(xpath);
XmlNode node2 = root.SelectSingleNode(xpath);
// These all return null
http://stackoverflow.com/documentation/xpath/2324/namespaces#t=201608050604347342848 –