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.
It would be much more useful to restructure your XML as described by the 2nd poster.

With that structure, you could easily do something like this (nodRoot is the User\_Security node):

```
foreach (XmlNode nodUser in nodRoot.ChildNodes)
{
   string userName = nodUser.Attributes["Name"].Value;
   foreach (XmlNode nodGroup in nodUser)
   {
      string groupName = nodGroup.InnerText;
      // do something with userName and groupName here
   }
}

```