private void AppendXMLChildren(XmlDocument doc, XmlNode xmlParent, TOKBranch tokParent) { foreach (TOKNode tokNode in tokParent.Nodes) { XmlNode xmlNode = null; if (tokNode.GetType() == typeof(TOKBranch)) { xmlNode = doc.CreateElement("TOKBranch"); AppendXMLChildren(doc, xmlNode, (TOKBranch)tokNode); } else { xmlNode = doc.CreateElement("TOKLeaf"); String nodeText = ((TOKLeaf)tokNode).Text; if (nodeText == null) { nodeText = ""; } XmlNode xmlText = doc.CreateTextNode(nodeText); xmlNode.AppendChild(xmlText); } XmlNode xmlName = doc.CreateAttribute("name"); xmlName.Value = tokNode.Name; xmlNode.Attributes.SetNamedItem(xmlName); xmlParent.AppendChild(xmlNode); } }
private void AppendTOKChildren(XmlDocument doc, XmlNode xmlParent, TOKBranch tokParent) { foreach (XmlNode xmlNode in xmlParent.ChildNodes) { if (xmlNode.NodeType == XmlNodeType.Element) { TOKNode tokNode = null; if (xmlNode.Name == "TOKBranch") { TOKBranch tokBranch = new TOKBranch(); AppendTOKChildren(doc, xmlNode, tokBranch); tokNode = tokBranch; } else { TOKLeaf tokLeaf = new TOKLeaf(); if (xmlNode.FirstChild?.NodeType == XmlNodeType.Text) { XmlText xmlText = (XmlText)xmlNode.FirstChild; tokLeaf.Text = xmlText.Value; tokNode = tokLeaf; } } XmlNode xmlName = xmlNode.Attributes.GetNamedItem("name"); if (xmlName != null) { tokNode.Name = xmlName.Value; } tokParent.Nodes.Add(tokNode); } } }
private void removeToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView.SelectedNode.Tag?.GetType() != typeof(TOKRoot)) { TOKBranch tokParent = (TOKBranch)treeView.SelectedNode.Parent?.Tag; if (tokParent != null) { tokParent.Nodes.Remove((TOKNode)treeView.SelectedNode.Tag); } treeView.SelectedNode.Remove(); } }
private void addLeafToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView.SelectedNode.Tag?.GetType() != typeof(TOKLeaf)) { TOKLeaf leaf = new TOKLeaf(); TOKBranch tokParent = (TOKBranch)treeView.SelectedNode.Tag; tokParent.Nodes.Add(leaf); TreeNode treeNode = makeTreeNode(leaf); treeView.SelectedNode.Nodes.Add(treeNode); treeView.SelectedNode = treeNode; } }
private TreeNode makeTreeNode(TOKNode tokNode) { TreeNode treeNode = new TreeNode(tokNode.Name); treeNode.Tag = tokNode; if (tokNode.GetType() != typeof(TOKLeaf)) { TOKBranch tokBranch = (TOKBranch)tokNode; foreach (TOKNode childTokNode in tokBranch.Nodes) { TreeNode childTreeNode = makeTreeNode(childTokNode); treeNode.Nodes.Add(childTreeNode); } } return(treeNode); }