c# read string as xml code example

Example 1: string to xml c#

string test = "<body><head>test header</head></body>";

XmlDocument xmltest = new XmlDocument();
xmltest.LoadXml(test);

XmlNodeList elemlist = xmltest.GetElementsByTagName("head");

string result = elemlist[0].InnerXml; 

//result -> "test header"

Example 2: How to read a XML on C#

XmlDocument doc = new XmlDocument();
            doc.Load(path);
            doc.Save(Console.Out);

            foreach (XmlNode node in doc.DocumentElement)
            {
                string word_name = node.Attributes[0].Value;
                string word_translation = node["name of node"].InnerText;
            }