C# 将XML转换为数组列表..C
我有一个XML字符串 ViewEmployees 编辑员工 转移 视点偏移 移位 删除移位C# 将XML转换为数组列表..C,c#,asp.net,.net,xml,C#,Asp.net,.net,Xml,我有一个XML字符串 ViewEmployees 编辑员工 转移 视点偏移 移位 删除移位 这就是你想要的吗???令人惊讶的是,在这个话题上没有任何问题。。。无论如何,请解释为什么需要ArrayList作为结果?来获取列表中的角色和权限。string[]角色=,,string[]权限=…可能重复的可能重复的可能重复的我遇到问题有多个根元素。第1行XDocument doc=XDocument.Loadnew StringReadertestString;xml字符串没有根元素。这个xml来自不
这就是你想要的吗???令人惊讶的是,在这个话题上没有任何问题。。。无论如何,请解释为什么需要ArrayList作为结果?来获取列表中的角色和权限。string[]角色=,,string[]权限=…可能重复的可能重复的可能重复的我遇到问题有多个根元素。第1行XDocument doc=XDocument.Loadnew StringReadertestString;xml字符串没有根元素。这个xml来自不同的源吗?如果不使用根元素将其包围Yes不使用根元素将其包围。testString=+testString+;在创建XDocument之前添加此行
testString = "<root>" + testString + "</root>";
XDocument doc = XDocument.Load(new StringReader(testString));
var arrayList = doc.Descendants("Role")
.Select(a => new Role{
Name = a.Attribute("name").Value,
Permissions = a.Descendants("PermissionName").Select(x=> x.Value).ToList()
}).ToArray();
public class Role{
public string Name{get;set;}
public List<string> Permissions{get;set;}
}