Skip to content

Instantly share code, notes, and snippets.

@donfreiday
Created November 11, 2019 17:32
Show Gist options
  • Save donfreiday/a6ba7da685d1e822f976c3abb3e04b7a to your computer and use it in GitHub Desktop.
Save donfreiday/a6ba7da685d1e822f976c3abb3e04b7a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Xml;
namespace xml1
{
class Program
{
static void Main(string[] args)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("https://www.w3schools.com/xml/simple.xml");
XmlNode root2 = xmlDoc.DocumentElement;
foreach (XmlNode node in root2.ChildNodes)
Traverse(node.ChildNodes);
}
private static void Traverse(XmlNodeList nodes)
{
foreach (XmlNode node in nodes)
{
if (node.NodeType == XmlNodeType.Element)
{
Console.WriteLine($"Node name: {node.Name,12} | Node text value: {node.InnerText,20}");
}
Traverse(node.ChildNodes);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment