TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jay Kamble
NA
23
3.7k
Reading Xml using Dom Approach and storing it in Dictionary
Mar 12 2017 5:35 AM
I have this Following XML File:
<Depts>
<Dept Name="Admin">
<Emps>
<Emp>1</Emp>
<Emp>8</Emp>
</Emps>
</Dept>
<Dept Name="HR">
<Emps>
<Emp>3</Emp>
</Emps>
</Dept>
<Dept Name="Operation">
<Emps>
<Emp>5</Emp>
<Emp>9</Emp>
</Emps>
</Dept>
</Depts>
And I have written this program using DOM to read and store the data into dictionary. But, while printing I am not getting any output. The console remains Blank.
The code is below:
Dictionary<string, int> dictionary = new Dictionary<string, int>();
XmlDocument document = new XmlDocument();
document.Load("Employee.xml");
XmlNodeList node1 = document.GetElementsByTagName("Dept Name");
foreach (var item in node1)
{
XmlNodeList node2 = document.GetElementsByTagName("//Emps/Emp");
foreach (var item1 in node2)
{ dictionary.Add(item.ToString(),Convert.ToInt32(item1.ToString()));
}
}
foreach (var item in dictionary)
{
Console.WriteLine("Key= " + item.Key + "\nValues= " + item.Value );
}
Console.ReadLine();
Reply
Answers (
4
)
How to create a setup EXE with SQL server 2012 in C#
Window Application