Created
November 11, 2019 17:32
-
-
Save donfreiday/a6ba7da685d1e822f976c3abb3e04b7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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