在运行时将属性添加到树 [英] adding attributes to tree at runtime

查看:71
本文介绍了在运行时将属性添加到树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个包含许多节点和属性的xml树.我想在运行时根据我们选择的节点将属性添加到该节点.有人可以帮忙吗?


i have a xml tree with many nodes and attributes.i want to add attributes to the node at runtime based on the node we select. can anyone help?

推荐答案

http://www .functionx.com/vcsharp2003/xml/Lesson08.htm [ ^ ]


XmlDocument doc = new XmlDocument();
           doc.Load("D://gokul/projects/New Folder/xmltree/xmltree/tree.xml");
           string tag = txttag.Text;
            string val = txtval.Text;
            XmlNodeList lis = doc.SelectNodes("//ContentNode[@name]");
            t = TreeView1.SelectedNode.Text;
           TreeNode nd=TreeView1.SelectedNode;
           XmlAttribute attr = doc.CreateAttribute(tag);
           attr.Value = val;
           foreach (XmlNode n in lis)
           {
               string attrVal = n.Attributes["name"].Value;
               XmlNode atlst = n.ChildNodes.Item(0);
               if (t==attrVal )
               {

                   n.Attributes.Append(attr);

                   doc.Save("D:/gokul/projects/New Folder/xmltree/xmltree/tree.xml");
               }}



这将从两个txt框中读取值,并获取TAG及其值的值.然后它将特定的属性添加到选定的节点.



this will read the values from two txt boxes and get the values for TAG and its VALUE. and then it ll add that particular attribute to the node which is selected.


这篇关于在运行时将属性添加到树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆