Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6838385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:35:26+00:00 2026-05-26T23:35:26+00:00

parse the xml file: XmlTextReader reader = new XmlTextReader(fileName); while (reader.Read()) { switch (reader.NodeType)

  • 0

parse the xml file:

XmlTextReader reader = new XmlTextReader(fileName);
while (reader.Read())
{
    switch (reader.NodeType)
    {
        case XmlNodeType.Element: // The node is an element.
            Console.Write("<" + reader.Name);
            Console.WriteLine(">");
            break;
        case XmlNodeType.Text: //Display the text in each element.
            Console.WriteLine(reader.Value);
            break;
        case XmlNodeType.EndElement: //Display the end of the element.
            Console.Write("</" + reader.Name);
            Console.WriteLine(">");
            break;
    }
}

How do i now enter nodes to get a tree view of the xml file i’m parsing? This is what i have thus far:

<TreeView Margin="177,61" Name="myTreeView" ItemsSource="{Binding XPath=XmlNodeType.Element}" >
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding XPath=XmlNodeType.Element}">
            <TextBlock Text="{Binding XPath=XmlNodeType.Text}" />
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

but nothing shows up…. just don’t understand how to add nodes i guess…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:35:26+00:00Added an answer on May 26, 2026 at 11:35 pm

    You have to add the nodes in code behind like that:

    var newNode = new TreeViewItem
    {
        Header = "New Node"
    };
    myTreeView.Items.Add(newNode);
    

    This adds a node to the top of the tree. If you want to build a hierarchy you have to add the node at the appropiate position like that:

    // Find the node you want to have as parent.
    var parentNode = myTreeView.Items.Cast<TreeViewItem>().FirstOrDefault(item => item.Header = "Parent Node");
    if (parentNode != null)
    {
        var newNode = new TreeViewItem
        {
            Header = "New Node"
        };
        parentNode.Items.Add(newNode);
    }
    

    BTW: I would use to x:Name Property to name the elements in Xaml, sometimes there is some trouble in code behind when you use only Name

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I parse an xml file containing books, for each new node I go: Book
It is easy to read an XML file and get the exact Node Text,
I am using C#'s xmlTextReader to parse an RSS xml file. It works fine
How to parse xml file in my junit selenium test case using eclipse, I
Hi I need to parse XML file using jquery. I created read and display
I need to parse a xml file which is practically an image of a
When I parse my xml file (variable f) in this method, I get an
I am attempting to parse a XML file using Javascript and I'm running into
I am using ElementTree to parse a XML file. In some fields, there will
I'm trying to fetch and parse an XML-file through JavaScript. I don't control the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.