Question: I'm a c# learner and now I've been facing this situation:

Here is the sample of xml I'm working on

```
<User_Security>
  <bob>
    <group>s1, a2, b3</group>
  </bob>
  <alice>
    <group>y3, c2</group>
  </alice>
</User_Security>

```

As you can see it uses the people as tag name not the tag data, so I cannot use getElementByTagName() by XmlDocument

How can I do to parse both name and the groups they belong?

Answer: 
Edit: I know that this doesn't answer the exact question of how to solve the problem with your current XML; but as many people have commented, your XML is subject to malformation and will cause you a lot of problems. I've worked with XML far more than any sane person should be coerced into doing and the advice I offer will save you a lot of heartache.

Good luck!

What I would do is use attributes and maybe an XSD schema.

Make it like this

```
<User_Security>
    <user name="Bob">
        <group>c1</group>
        <group>c2</group>
        <group>c3</group>
    </user>
    <user name="Alice">
        <group>c1</group>
        <group>c2</group>
    </user>
</User_Security>

```

You can use a XSD to say that the file is allowed multiple groups in a user; I'll find an example and post it in an edit.

Edit: An XSD fragment would look something like this, but you'll have to learn about the whole concept:

```
<xs:element name="user">
    <xs:attributename="name" type="xs:string" />
    <xs:complexType>
        <xs:choice>
            <xs:element name="group" type="xs:string" minoccurs="1" maxoccurs="unbounded"/>
        </xs:choice>
    </xs:complexType>
</xs:element>

```

An alternate way to do this block would be:

```
<xs:element name="user">
    <xs:attributename="name" type="xs:string" />
    <xs:simpleType name="SKU">
        <xs:restriction base="xs:string" />
    </xs:simpleType>
</xs:element>

```

This lets you validate your XML input and ensure that your user node must use a name attribute and that it can have 1..many Groups which must be strings.
this will parse out what you want...

```
        string xml = "<User_Security><bob><group>s1, a2, b3</group></bob><alice><group>y3, c2</group></alice></User_Security>";
        var e = XElement.Load(new XmlTextReader(xml, XmlNodeType.Element, null));

       var users = e.Elements()
        .Select(x => 
            new {
                Name = x.Name, 
                Groups = x.Element("group").Value.Split(new[] { ',' })
                         .Select(s => s.Trim())
                         .ToList() 
            }).ToList();

users.ForEach(u =>
    {
        Console.WriteLine(u.Name);
        u.Groups.ForEach(g => Console.WriteLine(" - " + g));
    });

```