XML read/write

Hello
Dose any one know how to read from and write to an XML file from the C# code. I need to make a program to interact with a server I have and the only way I can get the information out/in of it is in XML files.
Thank you
IanR

In an ideal case, you’d have an XSD which you can use to generate the object(s) so you can retrieve the content directly into an object.
If you don’t have an XSD it gets messy, because you’re more or less flying blind. In that case, maybe something along the lines of:

        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

        doc.Load(fileName);

        foreach (XmlNode node in doc.DocumentElement.ChildNodes)
        {
            if (node.Name == "whatever_name_your_node_has")
            {
                //Do something with the node data
            }
        }
1 Like