private static NTreeViewItem CreateTreeViewItem(NXmlNode node) { // Create a tree view item for the current XML node NTreeViewItem item; switch (node.NodeType) { case ENXmlNodeType.CDATA: case ENXmlNodeType.Comment: case ENXmlNodeType.Document: item = new NTreeViewItem(node.Name); break; case ENXmlNodeType.Declaration: case ENXmlNodeType.Element: string text = node.Name; NXmlElement element = (NXmlElement)node; INIterator <NKeyValuePair <string, string> > attributesIter = element.GetAttributesIterator(); if (attributesIter != null) { // Append the element attributes StringBuilder sb = new StringBuilder(text); while (attributesIter.MoveNext()) { sb.Append(" "); sb.Append(attributesIter.Current.Key); sb.Append("=\""); sb.Append(attributesIter.Current.Value); sb.Append("\""); } text = sb.ToString(); } item = new NTreeViewItem(text); break; case ENXmlNodeType.Text: item = new NTreeViewItem("Text: \"" + ((NXmlTextNode)node).Text + "\""); break; default: throw new Exception("New ENXmlNodeType?"); } // Traverse the node's children and create a child item for each of them INIterator <NXmlNode> iter = node.GetChildNodesIterator(); if (iter != null) { while (iter.MoveNext()) { NTreeViewItem childItem = CreateTreeViewItem(iter.Current); item.Items.Add(childItem); } } // Return the created tree view item return(item); }