public void Write(IEnumerable <SharpRow> rows) { var settings = new System.Xml.XmlWriterSettings { Indent = true, Encoding = _encoding }; _writer = System.Xml.XmlWriter.Create(_dest, settings); _writer.WriteStartDocument(); foreach (var row in rows) { WriteRow(row); } if (_commentBlock.Count > 0) { WriteCommentBlock(); } while (_nodeStack.Count > 0) { _writer.WriteEndElement(); _nodeStack.Dequeue(); } _writer.WriteEndDocument(); _writer.Flush(); _writer = null; }
public IEnumerable <SharpRow> InsertParentRows(IEnumerable <SharpRow> rows, bool skipFirstParentRow = false) { SharpNodeStack stack = new SharpNodeStack(); foreach (var row in rows) { var nodeRow = row as SharpNodeRow; if (nodeRow == null) { yield return(row); continue; } if (skipFirstParentRow) { stack.Enqueue(nodeRow.Node); skipFirstParentRow = false; yield return(row); continue; } if (stack.Top == nodeRow.Node.Parent) { if (!nodeRow.Node.IsValueNode) { stack.Enqueue(nodeRow.Node); } yield return(row); continue; } while (stack.Top != null && !stack.Top.HasDescendant(nodeRow.Node)) { stack.Dequeue(); } if (stack.Top == null || stack.Top.HasDescendant(nodeRow.Node)) { var nodes = nodeRow.Node.PathTo(stack.Top); foreach (var node in nodes) { stack.Enqueue(node); yield return(new SharpNodeRow(node)); } if (!nodeRow.Node.IsValueNode) { stack.Enqueue(nodeRow.Node); } yield return(row); } } }