Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to represent xml document on treeviewer using c#

how to represent xml document on treeviewer using c#

Scheduled Pinned Locked Moved C#
csharphtmlxmlhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    panter_rose
    wrote on last edited by
    #1

    i use this code to represente xml document oon treeViewer but the attributes don't apprae in treeViewer can you help me try { // Create a DOM Document and load the XML data into it. XmlDocument dom = new XmlDocument(); dom.Load(textBox1.Text); // Initialize the TreeView control. treeView1.Nodes.Clear(); treeView1.Nodes.Add(new TreeNode(dom.DocumentElement.Name)); TreeNode tNode = new TreeNode(); tNode = treeView1.Nodes[ 0 ]; // Populate the TreeView with the DOM nodes. AddNode(dom.DocumentElement, tNode); treeView1.ExpandAll(); } catch(XmlException xmlEx) { MessageBox.Show(xmlEx.Message); } catch(Exception ex) { MessageBox.Show(ex.Message); } private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; int i; // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { nodeList = inXmlNode.ChildNodes; for(i = 0; i<=nodeList.Count - 1; i++) { xNode = inXmlNode.ChildNodes[ i ]; inTreeNode.Nodes.Add(new TreeNode(xNode.Name)); tNode = inTreeNode.Nodes[ i ]; AddNode(xNode, tNode); } } else { // Here you need to pull the data from the XmlNode based on the // type of node, whether attribute values are required, and so forth. inTreeNode.Text = (inXmlNode.OuterXml).Trim(); } }

    P 1 Reply Last reply
    0
    • P panter_rose

      i use this code to represente xml document oon treeViewer but the attributes don't apprae in treeViewer can you help me try { // Create a DOM Document and load the XML data into it. XmlDocument dom = new XmlDocument(); dom.Load(textBox1.Text); // Initialize the TreeView control. treeView1.Nodes.Clear(); treeView1.Nodes.Add(new TreeNode(dom.DocumentElement.Name)); TreeNode tNode = new TreeNode(); tNode = treeView1.Nodes[ 0 ]; // Populate the TreeView with the DOM nodes. AddNode(dom.DocumentElement, tNode); treeView1.ExpandAll(); } catch(XmlException xmlEx) { MessageBox.Show(xmlEx.Message); } catch(Exception ex) { MessageBox.Show(ex.Message); } private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; int i; // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { nodeList = inXmlNode.ChildNodes; for(i = 0; i<=nodeList.Count - 1; i++) { xNode = inXmlNode.ChildNodes[ i ]; inTreeNode.Nodes.Add(new TreeNode(xNode.Name)); tNode = inTreeNode.Nodes[ i ]; AddNode(xNode, tNode); } } else { // Here you need to pull the data from the XmlNode based on the // type of node, whether attribute values are required, and so forth. inTreeNode.Text = (inXmlNode.OuterXml).Trim(); } }

      P Offline
      P Offline
      PicklesTheClown
      wrote on last edited by
      #2

      Add a section that processes attributes similar to the processing of child nodes. Something like...

        if (inXmlNode.Attributes != null)
        {
          foreach (XmlAttribute attribute in inXmlNode.Attributes)
          {
            inTreeNode.Nodes.Add(new TreeNode(attribute.Name));
          }
        }
      
      P 1 Reply Last reply
      0
      • P PicklesTheClown

        Add a section that processes attributes similar to the processing of child nodes. Something like...

          if (inXmlNode.Attributes != null)
          {
            foreach (XmlAttribute attribute in inXmlNode.Attributes)
            {
              inTreeNode.Nodes.Add(new TreeNode(attribute.Name));
            }
          }
        
        P Offline
        P Offline
        panter_rose
        wrote on last edited by
        #3

        i am biginer in c# i don't know whre place the code that you give me he^ple me please

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups