Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #read #xml #file
ADD COMMENT
Topic
Name
6+2 =