private void ParseItems(XElement root, int level, XNamespace ns, EpubPath path) { foreach (XElement navPoint in root.Elements(ns + "navPoint")) { XElement text = navPoint.Elements(ns + "navLabel").Elements(ns + "text").FirstOrDefault(); if (text == null) { continue; } XAttribute srcAttr = navPoint.Elements(ns + "content").Attributes("src").FirstOrDefault(); if (srcAttr == null) { continue; } string cleanSource = srcAttr.Value; int length = srcAttr.Value.IndexOf("#", StringComparison.Ordinal); length = length > -1 ? length : cleanSource.Length; cleanSource = cleanSource.Substring(0, length); string key = path + cleanSource; if (Anchors.ContainsKey(key)) { int num = Anchors[key]; var item = new BookChapter { Level = level, Title = CleanText(text.Value), TokenID = num }; Chapters.Add(item); ParseItems(navPoint, level + 1, ns, path); } } }