Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
            }
Comment

read xml file c#

XmlDocument doc = new XmlDocument();
using (StreamReader streamReader = new StreamReader(path_name, Encoding.UTF8))
{
	contents = streamReader.ReadToEnd();
}
doc.LoadXml(contents);
Comment

c# read xml file

// Include this namespace
using System.Xml;

// Read an XML From file
XmlDocument doc = new XmlDocument();
doc.Load("c:	emp.xml");

// Or from string
doc.LoadXml("<xml>something</xml>");

// you can find a node like this
XmlNode node = doc.DocumentElement.SelectSingleNode("/book/title");
// or
foreach(XmlNode node in doc.DocumentElement.ChildNodes){
   string text = node.InnerText; //or loop through its children as well
}

// and you can read the text inside the node
string text = node.InnerText;
// or read the attribute (the ? there is checking if it's null or not)
string attr = node.Attributes["theattributename"]?.InnerText

/// Credit to Wolf5 and George D Girton
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# paste from clipboard 
Csharp :: random seed in c# 
Csharp :: How to get the world position of the edge of an object? 
Csharp :: c# download string url 
Csharp :: c# string to enum conversion 
Csharp :: how to write a variable in console c# 
Csharp :: basic movement script unity 
Csharp :: increase variable C# 
Csharp :: how to create an array in c# 
Csharp :: prettier inst working c# 
Csharp :: How can you learn C# on your own 
Csharp :: parse int in c# 
Csharp :: C# HttpClient POST request 
Csharp :: delayed function unity 
Csharp :: programmatically write bash script from c# 
Csharp :: words counter c# 
Csharp :: c# date 
Csharp :: c# restart app 
Csharp :: unity look at target 
Csharp :: c# hello world 
Csharp :: weighted random c# 
Csharp :: httppostedfilebase in .net core 3.1 
Csharp :: linq distinct count 
Csharp :: c# list to string join 
Csharp :: convert iformfile to byte array c# 
Csharp :: how to say hello world in c# 
Csharp :: bytes to httppostedfilebase c# 
Csharp :: xamarin hide back button 
Csharp :: c# initialize empty array 
Csharp :: c# mathf.ceiling 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =