C# 获取xml文件中的路径
我的组合框中填充了 6.70_扩展 7.00_扩展 7.10.000_小费 7.10_扩展 如果我的组合框选择的值是C# 获取xml文件中的路径,c#,xml,C#,Xml,我的组合框中填充了 6.70_扩展 7.00_扩展 7.10.000_小费 7.10_扩展 如果我的组合框选择的值是6.70_扩展名,并且在按钮事件期间,如何从带有“6.70_扩展名”的xml文件(antcheckin.xml)中选择路径?例如:从xml文件中选择“C:\Work\6.70\u Extensions\folder” 注意:组合框的选定值为 var buildStream=((DataRowView)BuildstreamComboBox.SelectedItem.Row[“val
6.70_扩展名
,并且在按钮事件期间,如何从带有“6.70_扩展名”
的xml文件(antcheckin.xml)中选择路径?例如:从xml文件中选择“C:\Work\6.70\u Extensions\folder”
注意:组合框的选定值为
var buildStream=((DataRowView)BuildstreamComboBox.SelectedItem.Row[“value”].ToString()
基本上,选择此路径后,我将使此文件夹成为非只读文件夹
这就是我之前所做的(注意:这个组合框最初没有填充xml数据,我设法用xml数据填充它,因此我需要一个新的代码,因为我现在不能依赖于所选的索引)
antcheckin.xml:
<project>
<buildmachine4>
<checkout1 exe="wco" folder='-f -R "C:/Work/6.70_Extensions/folder/"'/>
<checkout2 exe="wco" folder='-f -R "C:/Work/7.00_Extensions/folder/"'/>
</buildmachine4>
<buildmachine5>
<checkout3 exe="wco" folder='-f -R "C:/Work/7.10.000_Tip/folder/"'/>
</buildmachine5>
</project>
使用LINQtoXML并在XML中搜索属性值 如下所示
from el in root.Elements("rootlement")
where
(from add in el.Descendants()
where
add.Attribute("MyAttribute") != null
&&
add.Attribute("MyAttribute").Value.Contains("ZXCV")
select add)
.Any()
select el;
但是我怎样才能得到
“C:/Work/6.70_Extensions/folder”
?因为前面有-f
和-R
it@jeremychan-将-f和-r替换为attribute@jeremychan您能够编辑XML文件吗?需要旗帜吗?如果是,我建议您从文件夹属性中分离出-f
和-R
标志。例如,类似这样的东西(我假设了标志的含义):
。hi-f和-r指的是其他东西
public void BuildButton_Click(object sender, RoutedEventArgs e)
{
// the following is used to ensure the folder checked out is now not "read only"
// load your XML
XDocument doc = XDocument.Load(@"C:\Work\ANTCheckIN.xml");
XElement mainItem = doc.Descendants("project")
.Where(mi => mi.Attribute("folder").Value.Contains(buildStream)
....
//what should be added here?
}
from el in root.Elements("rootlement")
where
(from add in el.Descendants()
where
add.Attribute("MyAttribute") != null
&&
add.Attribute("MyAttribute").Value.Contains("ZXCV")
select add)
.Any()
select el;