private void CreateFlatTextRanges() { foreach (XDocument document in this.documents) { FlatTextRange currentRange = null; foreach (XElement run in document.Descendants(FlatConstants.RunElementName)) { if (!run.HasElements) { continue; } FlatText flatText = FlattenRunElement(run); if (flatText == null) { continue; } // If current Run doesn't belong to same parent (like paragraph, hyperlink, etc.) // create new FlatTextRange, otherwise use current one. if (currentRange == null || currentRange.Parent != run.Parent) { currentRange = this.CreateFlatTextRange(run.Parent); } currentRange.AddFlatText(flatText); } } }