public Node ProcessElement(XElement startEl) { if (IsComplex(startEl)) { CompositeNode top = new CompositeNode(startEl.Name.LocalName); foreach (var attr in startEl.Attributes()) { var leaf = new LeafNode(typeof(String), attr.Name.LocalName, attr.Value); top.AddChildNode(leaf); } foreach (var childEl in startEl.Elements()) { var childNode = ProcessElement(childEl); top.AddChildNode(childNode); } return top; } else { LeafNode top = new LeafNode(typeof(String), "", ""); return top; } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="reader"></param> /// <param name="prefix"></param> public void PopulateTree(CompositeNode root, IDataReader reader, String prefix) { string[] fields = GetFields(reader); int[] indexesToSkip = FindDuplicateFields(fields); IndexedNode indexNode = new IndexedNode(prefix); int row = 0; while(reader.Read()) { CompositeNode node = new CompositeNode(row.ToString()); for(int i=0; i<reader.FieldCount; i++) { // Is in the skip list? if (Array.IndexOf(indexesToSkip, i) >= 0) continue; // Is null? if (reader.IsDBNull(i)) continue; Type fieldType = reader.GetFieldType(i); node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i))); } indexNode.AddChildNode(node); row++; } root.AddChildNode(indexNode); }
public CompositeNode BuildNode(XDocument doc) { var rootNode = new CompositeNode("root"); rootNode.AddChildNode(ProcessElement(doc.Root)); return rootNode; }
private static CompositeNode GetParamsNode(int expectedValue) { CompositeNode paramsNode = new CompositeNode("root"); IndexedNode listNode = new IndexedNode("myList"); paramsNode.AddChildNode(listNode); listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue)); return paramsNode; }
private IndexedNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName) { Node node = parent.GetChildNode(nodeName); if (node != null && node.NodeType != NodeType.Indexed) { throw new BindingException("Attempt to create or obtain an indexed node " + "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType); } if (node == null) { node = new IndexedNode(nodeName); parent.AddChildNode(node); } return((IndexedNode)node); }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="reader"></param> /// <param name="prefix"></param> public void PopulateTree(CompositeNode root, IDataReader reader, String prefix) { string[] fields = GetFields(reader); int[] indexesToSkip = FindDuplicateFields(fields); var indexNode = new IndexedNode(prefix); int row = 0; while (reader.Read()) { var node = new CompositeNode(row.ToString()); for (int i = 0; i < reader.FieldCount; i++) { // Is in the skip list? if (Array.IndexOf(indexesToSkip, i) >= 0) { continue; } // Is null? if (reader.IsDBNull(i)) { continue; } Type fieldType = reader.GetFieldType(i); node.AddChildNode(new LeafNode(fieldType, fields[i], reader.GetValue(i))); } indexNode.AddChildNode(node); row++; } root.AddChildNode(indexNode); }
private IndexedNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName) { Node node = parent.GetChildNode(nodeName); if (node != null && node.NodeType != NodeType.Indexed) { throw new BindingException("Attempt to create or obtain an indexed node " + "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType); } if (node == null) { node = new IndexedNode(nodeName); parent.AddChildNode(node); } return (IndexedNode) node; }
private void AddLeafNode(CompositeNode parent, Type type, String nodeName, object value) { parent.AddChildNode(new LeafNode(type, nodeName, value)); }
public void AddToRoot(CompositeNode rootNode, XDocument doc) { var top = ProcessElement(doc.Root); rootNode.AddChildNode(top); }