-1

i have a XML string

<Role name="Admin">
    <PermissionName>ViewEmployees</PermissionName>
    <PermissionName>EditEmployees</PermissionName>
</Role>
<Role name="HR Manager">
    <PermissionName>Shifts</PermissionName>
    <PermissionName>ViewShifts</PermissionName>
    <PermissionName>AddShifts</PermissionName>
    <PermissionName>DeleteShifts</PermissionName>
</Role>

want to convert it into array list..please help.

diiN__________
  • 7,393
  • 6
  • 42
  • 69
LuckyS
  • 553
  • 5
  • 17
  • It is surprising that there are no existing questions on this topic... In any way please explain why you need ArrayList as result? – Alexei Levenkov May 20 '16 at 05:29
  • to get roles and permission in list . string[] roles= ,,string[] permissions=.. – LuckyS May 20 '16 at 05:29
  • Possible duplicate of [How does one parse XML files?](http://stackoverflow.com/questions/55828/how-does-one-parse-xml-files) – Adam May 20 '16 at 06:14
  • Possible duplicate of [Reading Xml with XmlReader in C#](http://stackoverflow.com/questions/2441673/reading-xml-with-xmlreader-in-c-sharp) – Ilja Everilä May 20 '16 at 07:12

1 Answers1

3
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;}
}

Is this what you are looking for??

Pratap Bhaskar
  • 408
  • 3
  • 11