/// <summary> /// Gets a count of the number of times the given node /// repeats in the list of children nodes /// </summary> /// <param name="childNode">ChildNode t get count of</param> /// <returns>Coutn of the number of times nodes with the same Name/Namespace appear</returns> public int GetCountOfRepeatingChildNodes(ViewerNode childNode) { // Sanity check parameters if (childNode == null) { throw new ArgumentNullException("A valid ViewerNode must be supplied"); } // Check if this is a repeating node if (childNode.OccurrenceIndex == -1) { return(0); } // Get a count of child nodes with the same name int nodeCount = 0; for (int nodeIndex = 0; nodeIndex < _childNodes.Count; nodeIndex++) { if ((string.Compare(_childNodes[nodeIndex].LocalName, childNode.LocalName, true) == 0) && (string.Compare(_childNodes[nodeIndex].Namespace, childNode.Namespace, true) == 0)) { nodeCount++; } } return(nodeCount); }
/// <summary> /// Builds the tree view from the current XmlDocument /// </summary> private void BuildTreeView() { trvXml.Nodes.Clear(); _rootNode = new ViewerNode(_doc.DocumentElement, null); BuildTreeView(trvXml, _rootNode, null); trvXml.Nodes[0].Expand(); }
/// <summary> /// Creates an instance of a ViewerNode from the given occurrence of an XmlNode in a list /// </summary> /// <param name="originalNode">Node to create ViewerNode from</param> /// <param name="parent">Parent node of this node</param> /// <param name="occurrenceIndex">Occurrence in the list (1 based)</param> public ViewerNode(XmlNode originalNode, ViewerNode parent, int occurrenceIndex) { _originalNode = originalNode; _parent = parent; _occurrenceIndex = occurrenceIndex; Build(); }
/// <summary> /// Handles the event raised after a new tree node has been selected /// </summary> /// <param name="sender">Object raising the event</param> /// <param name="e">Event-specific parameters</param> private void trvXml_AfterSelect(object sender, TreeViewEventArgs e) { SetTreeViewContextMenuStates(sender as TreeView); if ((e.Node != null) && (e.Node.Tag != null)) { _selectedNode = (ViewerNode)e.Node.Tag; txtXPath.Text = _selectedNode.XPath; } }
/// <summary> /// Add a node to the tree view and processes any children /// </summary> /// <param name="vNode">ViewerNode to add</param> /// <param name="parentNode">Parent TreeView node to add new node to</param> private void BuildTreeView(TreeView trv, ViewerNode vNode, TreeNode parentNode) { if (vNode.NodeType == NodeType.Unknown) { return; } TreeNode node = null; if (vNode.NodeType == NodeType.Attribute) { if (vNode.AttributeType == AttributeType.None) { node = new TreeNode(vNode.ToString()); node.ForeColor = Color.Brown; node.ToolTipText = vNode.ToDetailsString(); } else { return; } } else if (vNode.NodeType == NodeType.Element) { node = new TreeNode(vNode.ToString()); node.ToolTipText = vNode.ToDetailsString(); } node.Tag = vNode; node.ContextMenuStrip = mnuTreeView; // Add attributes for (int attrIndex = 0; attrIndex < vNode.Attributes.Count; attrIndex++) { BuildTreeView(trv, vNode.Attributes[attrIndex], node); } // Add children for (int childIndex = 0; childIndex < vNode.ChildNodes.Count; childIndex++) { BuildTreeView(trv, vNode.ChildNodes[childIndex], node); } if (parentNode == null) { trv.Nodes.Add(node); } else { parentNode.Nodes.Add(node); } }
/// <summary> /// Shows this form as a modal dialog /// </summary> /// <param name="rootNode">Root node to generate test case from</param> /// <param name="currentFileName">The path to the xml file to use</param> /// <param name="schemaPath">The path to the xsd file to use</param> public void ShowDialog(ViewerNode rootNode, string currentFileName, string schemaPath) { _rootNode = rootNode; _currentFileName = currentFileName; _schemaPath = schemaPath; try { _currentFile = new FileInfo(_currentFileName); CreateBizUnitTestCase(); ShowDialog(); } catch (Exception ex) { MessageBox.Show("Unable to show the Test Case dialog because: " + ex.Message, "Unable to show the Test Case dialog ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Displays the results of the XPath Navigator in the Xpath results tree view /// </summary> /// <param name="xpi">XPathNodeIterator created using the XPath query</param> private void DisplayNavigator(XPathNodeIterator xpi) { if ((xpi != null) && (xpi.Count > 0)) { bool moreNodes = xpi.MoveNext(); while (moreNodes) { if (xpi.Current.NodeType == XPathNodeType.Text) { TreeNode node = new TreeNode("Result: " + xpi.Current.Value); node.ForeColor = Color.Brown; node.ContextMenuStrip = mnuTreeView; node.ToolTipText = node.Text; trvXpathResult.Nodes.Add(node); } else if (xpi.Current.NodeType == XPathNodeType.Attribute) { TreeNode node = new TreeNode("@" + xpi.Current.Name + ": " + xpi.Current.Value); node.ForeColor = Color.Brown; node.ContextMenuStrip = mnuTreeView; node.ToolTipText = node.Text; trvXpathResult.Nodes.Add(node); } else if (xpi.Current.NodeType == XPathNodeType.Element) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xpi.Current.OuterXml); ViewerNode vNode = new ViewerNode(doc.DocumentElement, null); BuildTreeView(trvXpathResult, vNode, null); } moreNodes = xpi.MoveNext(); } } else { trvXpathResult.Nodes.Add("Nothing found."); } }
/// <summary> /// Creates an instance of a ViewerNode from the given XmlNode /// </summary> /// <param name="originalNode">Node to create ViewerNode from</param> /// <param name="parent">Parent node of this node</param> public ViewerNode(XmlNode originalNode, ViewerNode parent) : this(originalNode, parent, -1) { }