<Tasks>
<AuxFiles>
<FileType AttachmentType='csv' FileFormat ='*.csv'>
</AuxFiles>
</Tasks>
如果我知道 AttachmentType
,在 C# 中获取 FileFormat
的语法是什么?
我们将不胜感激任何帮助。
最佳答案
我会使用 LINQ to XML:
var doc = XDocument.Load("file.xml");
var format = doc.Descendants("FileType")
.Where(x => (string) x.Attribute("AttachmentType") == type)
.Select(x => (string) x.Attribute("FileFormat"))
.FirstOrDefault();
如果没有匹配的元素,或者第一个具有匹配的 AttachmentType
的 FileType
没有 ,这将给出
属性。null
>FileFormat
关于c# - 使用 C# 读取 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7001752/