Reading from XML document C# with Example



Reading from XML document C# with Example

An example XML file 
 
 
 
 
 
 
 
 
 
 
Reading from this XML file: 
using System.Xml; 
using System.Collections.Generic; 
public static void Main(string fullpath) 
{ 
var xmldoc = new XmlDocument(); 
xmldoc.Load(fullpath); 
var oneValues = new List(); 
 

// Getting all XML nodes with the tag name 
var accountNodes = xmldoc.GetElementsByTagName("Account"); 
for (var i = 0; i < accountNodes.Count; i++) 
{ 
// Use Xpath to find a node 
var account = accountNodes[i].SelectSingleNode("./One"); 
if (account != null && account.Attributes != null) 
{ 
// Read node attribute 
oneValues.Add(account.Attributes["number"].Value); 
} 
} 
} 

0 Comment's

Comment Form

Submit Comment