Problemes dans l'affichages des attributs d'un xmldocument en treeViewer

moha_yougo Messages postés 40 Date d'inscription samedi 28 janvier 2006 Statut Membre Dernière intervention 1 avril 2006 - 14 févr. 2006 à 11:39
moha_yougo Messages postés 40 Date d'inscription samedi 28 janvier 2006 Statut Membre Dernière intervention 1 avril 2006 - 20 févr. 2006 à 09:04
je voulais charger un document xml dans treeViewer pour cela g fait ca:
mais les attribus ne saffiche pas
aidez moi svp

try
            {
                // Create a DOM Document and load the XML data into it.
                
                XmlDocument dom = new XmlDocument();
                
                dom.Load ("hello.xml");

                // 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();
            }
        }

2 réponses

Le_proprio_de_mykeyes Messages postés 60 Date d'inscription mardi 26 juillet 2005 Statut Membre Dernière intervention 16 avril 2006
19 févr. 2006 à 22:40
j'ai une source qui fonctionne sur "http://cyberquebec.ca/mykeys/aide/XmlToTreeview.cs"

David > Mykeys Administrateur
0
moha_yougo Messages postés 40 Date d'inscription samedi 28 janvier 2006 Statut Membre Dernière intervention 1 avril 2006
20 févr. 2006 à 09:04
c bon ça marche
merci
0
Rejoignez-nous