XML / C# Loop through nodes of the same name

I have this XML file with keys and values, and I currently loop through the XML doc, and I read all the data.

However, I have certain ‘keys’ or ‘Nodes’ that have the same keyname, but different (or same) values.
I need to loop through these same nodes within the same parent node.

<tile>
   <x>0</x>
   <y>1</y>
   <name>Grass</name>
   <entity>Tree</entity>
   <entity>Building</entity>
   <entity>Something</entity>
</tile>

I need to get X, Y and the Name, and an array/list of the entity.

Current code:

        XmlElement element = doc.DocumentElement;
        XmlNodeList nList = element.SelectNodes("/map/tile");
        foreach(XmlNode node in nList){
            int x = int.Parse(node["x"].InnerText);
            int y = int.Parse(node["y"].InnerText);
            String materialName = node["name"].InnerText;
            for(node["entity"] in allEntityNodesWithinThisTile){ }
        }

Thanks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s