Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将XML转换为数组列表..C_C#_Asp.net_.net_Xml - Fatal编程技术网

C# 将XML转换为数组列表..C

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来自不

我有一个XML字符串

ViewEmployees 编辑员工 转移 视点偏移 移位 删除移位
这就是你想要的吗???

令人惊讶的是,在这个话题上没有任何问题。。。无论如何,请解释为什么需要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;}
}