我正在尝试为 Xml 文件编写查询。这是我的输入 XML 文件:
<logentry
revision="10034">
<date>2009-10-07T03:45:38.000000Z</date>
<paths>
<path
kind="file"
action="M">/trunk/org.eclipse.mylyn.tasks/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java</path>
<path
kind="file"
action="M">/trunk/org.eclipse.mylyn.tasks/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java</path>
</paths>
</logentry>
我正在尝试过滤日期 2006-05-01 和 2007-09-01 之间的所有日志。我的输出应该是这样的:
10034 2009-10-07 BugzillaRepositoryConnectorTest.java,BugzillaRepositoryConnectorStandaloneTest.java
这意味着对于 date1 和 date2 之间的每个特定修订号,我希望获得来自 tag 的所有文件的列表。我使用正则表达式将文件名与路径分开。
这是我的代码:
using(System.IO.StreamWriter file1= new System.IO.StreamWriter( @"/home/datehistory"))
{XDocument log= XDocument.Load(@"/home/output.xml");
var selected= from logs in log.Descendants("logentry")
select new
{revno=logs.Attribute("revision").Value,
date=logs.Element("date").Value,
list1= {from files in logs.Element("paths").Element("path").Value
let match=Regex.Match(files,@"/([A-Za-z0-9\-]+.java)<",RegexOptions.IgnoreCase);
where match.Success
select new
{filename=match.Groups[1].Value }; }
???? "please help " where date between 2006-05-01 and 2007-09-01
};
foreach (var d in selected)
{
file1.Write(d.revno);
file1.Write("\t");
file1.Write(d.date);
file1.Write("\t");
foreach item in d.list1
{file1.write(item);
file1.write("\t"); }
file1.write("\n");
}