This xml blog helps you to read node from xml document.So first you need to import namespace system.Xml. Now create instance for xmldocument.This is the sample xml document through which you are going to read particular node.

              <class>
                    <standard>
                    1
                    <standard>
                    <teacher>
                        Shiva
                    <teacher>
                    <noofstudents>
                          80
                    <noofstudents>
               <class>
                

For example, i want to get teacher name from the above sample xml document.Here is the code to achieve it.

                       using System.Xml;
                       XmlDocument xmldoc=new XmlDocument();
                        string filename= "sample.xml";
                        xmldoc.Load(filename);
                        foreach(xmlnode node in xmldoc.GetElementsByTagName("class"))
                        {
                            foreach(xmlnode node1 in node.ChildNodes)
                            {
                                if(node1.Name="teacher")
                                {
                                    console.writeline("Teacher Name:" + node1.InnerText);
                                
                                }
        
                            }
                        
                         }
                    

This topic is regarding adding nodes to an existing xml document.Let us try this, my requirement is to add another standard in existing sample.xml document.

              <class>
                    <standard>
                    1
                    <standard>
                    <teacher>
                        Shiva
                    <teacher>
                    <noofstudents>
                          80
                    <noofstudents>    
               <class>
                

Here is the code to add node to an existing xml document.

                       using System.Xml;
                       XmlDocument xmldoc = new XmlDocument();
                       string filename = "sample.xml";
                       xmldoc.Load(filename);
                       XmlNode root = xmlDoc.DocumentElement;
                       XmlNode node = xmlDoc.SelectSingleNode("/class");

                        //create node and add value
                        XmlElement xestandard = xmlDoc.CreateElement("standard");
                        xestandard.InnerText =2;

                            //create node and add value
                        XmlElement xeteacher = xmlDoc.CreateElement("teacher");
                        xeteacher.InnerText ="Muruga";

                            //create node and add value
                        XmlElement xenoofstudents = xmlDoc.CreateElement("noofstudents");
                        xenoofstudents.InnerText =80;

                         node.AppendChild(xestandard);
                         node.AppendChild(xeteacher);
                         node.AppendChild(xenoofstudents);
      
                        //save back
                        xmlDoc.Save(filename);

                    

Finally you will see output like the below,

              <class>
                    <standard>
                    1
                    <standard>
                    <teacher>
                        Shiva
                    <teacher>
                    <noofstudents>
                          80
                    <noofstudents>
                    <standard>
                    2
                    <standard>
                    <teacher>
                        Muruga
                    <teacher>
                    <noofstudents>
                          80
                    <noofstudents>
               <class>