Hey,
I have tried Google, but no avail.
I have an XML file, say
<Items>
<item>
<id>1</id>
<name>test</name>
</item>
<item>
<id>2</id>
<name>othertest</name>
</item>
</Items>

I have a function Add(int id, string name). How would I read through every <item>, get the id and name, and call the add function.

Thanks

Import "System.Xml" namespace first: using System.Xml; And use this code to get the item name/id:

XmlDocument doc = new XmlDocument();
            doc.Load("C:\\xml.txt");

            XmlNodeList list = doc.GetElementsByTagName("item");

            int id = 0; 
            string name = string.Empty;

            foreach (XmlNode node in list)
            {
                id = int.Parse(node["id"].InnerText);
                name = node["name"].InnerText;

                Add(id, name);
            }

Sorted. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.