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 :: yanderedev 
Csharp :: system.windows.forms not found 
Csharp :: https request c# 
Csharp :: failed to read the request form. missing content-type boundary .net core 
Csharp :: how to verify the scene unity 
Csharp :: switch case c# 
Csharp :: OnMousedown unity ui 
Csharp :: unity instantiate prefab rotation 
Csharp :: c# is in array 
Csharp :: read all lines from txt c# 
Csharp :: 3d perlin noise unity 
Csharp :: c# convert int to string 
Csharp :: change dot net core web api routing 
Csharp :: unity exception 
Csharp :: unity joystick movement 
Csharp :: function on animation end unity 
Csharp :: Configure Automapper 
Csharp :: c# input 
Csharp :: c# get directory name from filename 
Csharp :: httpcontext in .net standard 
Csharp :: array join c# 
Csharp :: fluent assertions exception 
Csharp :: How can I return image from controller asp.net 
Csharp :: switch expression c# multiple cases 
Csharp :: show snackbar without scaffold flutter 
Csharp :: char to digit in java 
Csharp :: MissingPluginException (MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) 
Csharp :: c# binding add combobox with enum values 
Csharp :: C# async to sync 
Csharp :: subtract days c# 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =