Esempio n. 1
0
        private void BtnAttribRemove_Click(object sender, EventArgs e)
        {
            MyTreeNode node = seletedNode;
            XNamespace Xns  = node.xElement.Name.Namespace;

            try
            {
                if (listAttrib.SelectedItems.Count > 0 && node != null && MessageBox.Show("Do you want to remove selected Attribute(s)/Content?", "Remove", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (ListViewItem item in listAttrib.SelectedItems)
                    {
                        if (item.SubItems[0].Text.ToLower().Equals("<content>"))
                        {
                            seletedNode.xElement.SetValue("");
                        }
                        else if (node.xElement.Attribute(Xns + item.SubItems[0].Text) != null)
                        {
                            node.xElement.Attribute(Xns + item.SubItems[0].Text).Remove();//RemoveAttributes[item.Index]();
                        }
                    }
                    root.xElement.Save(TextOutFile.Text);
                    //MessageBox.Show("Removed", "Remove Attribute(s)");
                    showSuccessMessage(listAttrib.SelectedItems.Count + " Item(s) Removed.");
                    loadAttrib(node);
                    listAttrib.Focus();
                }
            }
            catch (Exception err)
            {
                showErrorMessage(err.Message);
            }
        }
Esempio n. 2
0
        private bool loadOutPutTree()
        {
            textAttribName.Text = "";
            textAttribVal.Text  = "";
            textNS.Text         = "";
            XElement element;

            try
            {
                element     = XElement.Load(TextOutFile.Text);
                textNS.Text = element.Name.Namespace.ToString();
                //XNamespace Xns=element.getna
                treeOutXML.Nodes.Clear();
                root = new MyTreeNode(element.Name.LocalName.ToString(), element);
                getInnerNode(root, element);
                treeOutXML.Nodes.Add(root);
                root.Expand();
                return(true);
            }
            catch (Exception err)
            {
                //Console.WriteLine(err.Message);
                showErrorMessage(err.Message);
                return(false);
            }
        }
Esempio n. 3
0
        private void treeOutXML_AfterSelect(object sender, TreeViewEventArgs e)
        {
            seletedNode = (MyTreeNode)e.Node;
            loadAttrib(seletedNode);
            XNamespace xns = seletedNode.xElement.Name.Namespace;

            textNS.Text         = seletedNode.xElement.Name.Namespace.ToString();
            textAttribName.Text = "";
            textAttribVal.Text  = "";
        }
Esempio n. 4
0
        private void getInnerNode(MyTreeNode root, XElement element)
        {
            MyTreeNode node;

            foreach (XElement item in element.Elements())
            {
//                ListItems.Items.Add(item.Value, "TRUE".Equals(item.Attribute("checked").Value.ToUpper()));
                node = new MyTreeNode(item.Name.LocalName.ToString(), item);
                root.Nodes.Add(node);
                getInnerNode(node, item);
            }
        }
Esempio n. 5
0
        private void BtnAttribEdit_Click(object sender, EventArgs e)
        {
            MyTreeNode          node         = seletedNode;
            XNamespace          Xns          = node.xElement.Name.Namespace;
            List <ListViewItem> ListSelected = new List <ListViewItem>();

            foreach (ListViewItem item in listAttrib.SelectedItems)
            {
                ListSelected.Add(item);
            }
            try
            {
                if (ListSelected.Count > 0 && node != null && MessageBox.Show("Do you want to edit selected Attribute(s)/Content?", "Remove", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (ListViewItem item in ListSelected)
                    {
                        if (item.SubItems[0].Text.ToLower().Equals("<content>"))
                        {
                            seletedNode.xElement.SetValue(textAttribVal.Text);
                            //item.SubItems[2].Text = textSearch.Text;
                        }
                        else
                        {
                            if (node.xElement.Attribute(Xns + item.SubItems[0].Text) != null && ListSelected.Count == 1 && !item.SubItems[0].Text.Equals(textAttribName.Text))
                            {
                                node.xElement.Attribute(Xns + item.SubItems[0].Text).Remove();
                                node.xElement.Add(new XAttribute(Xns + textAttribName.Text, ""));
                            }
                            node.xElement.SetAttributeValue(Xns + textAttribName.Text, textAttribVal.Text);
                        }
                    }
                    root.xElement.Save(TextOutFile.Text);
                    //MessageBox.Show("Sucessful...", "Edit Attribute(s)");
                    showSuccessMessage(ListSelected.Count + " Item(s) Edited.");
                    loadAttrib(node);
                    listAttrib.Focus();
                }
            }
            catch (Exception err)
            {
                showErrorMessage(err.Message);
            }
        }
Esempio n. 6
0
        private void loadAttrib(MyTreeNode node)
        {
            MyTreeNode   selectedNode = node;
            ListViewItem item         = null;

            listAttrib.Items.Clear();
            //adding contentenclosed by node
            if (!selectedNode.xElement.HasElements)
            {
                string[] row1 = { "<Content>", selectedNode.xElement.Value, "" };
                item = new ListViewItem(row1);
                listAttrib.Items.Add(item);
            }
            //adding attributes
            foreach (XAttribute attrib in selectedNode.xElement.Attributes())
            {
                string[] row = { attrib.Name.LocalName.ToString(), attrib.Value, "" };
                item = new ListViewItem(row);
                listAttrib.Items.Add(item);
            }
        }