public FileDocument Parse() { if (_parsed) { throw new InvalidOperationException("Parse can only be called once"); } var rootNode = new FileNode() { Level = -1, Parent = null, Tag = "ROOT" }; var currentNode = rootNode; FileNode node = null; while ((node = GetNode()) != null) { while (currentNode.Level >= node.Level) { if (currentNode.Parent == null) { throw new InvalidFileFormatException(_lineNumber, "invalid hierarchy structure"); } currentNode = currentNode.Parent; } //found the parent node currentNode.AddChild(node); currentNode = node; //move to the new node } var rootNodes = rootNode.ToList(); foreach (var n in rootNodes) { rootNode.RemoveChild(n); } _doc = new FileDocument(rootNodes); //do parsing _parsed = true; return(Document); }
public GedcomDocument(FileDom.FileDocument file) { _lazyFile = new Lazy <FileDocument>(() => file); }