private static async Task<EpubGuide> ReadGuideAsync(XmlReader reader)
        {
            EpubGuide result = new EpubGuide();

            while (await reader.ReadAsync() && !(reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "guide"))
            {
                if (reader.LocalName.ToLowerInvariant() == "reference")
                {
                    EpubGuideReference guideReference = new EpubGuideReference();
                    while (reader.MoveToNextAttribute())
                    {
                        switch (reader.LocalName.ToLowerInvariant())
                        {
                            case "type":
                                guideReference.Type = reader.Value;
                                break;
                            case "title":
                                guideReference.Title = reader.Value;
                                break;
                            case "href":
                                guideReference.Href = reader.Value;
                                break;
                        }
                    }
                    if (String.IsNullOrWhiteSpace(guideReference.Type))
                        throw new Exception("Incorrect EPUB guide: item type is missing");
                    if (String.IsNullOrWhiteSpace(guideReference.Href))
                        throw new Exception("Incorrect EPUB guide: item href is missing");
                    result.Add(guideReference);
                }
            }
            return result;
        }
示例#2
0
 private static EpubGuide ReadGuide(XmlNode guideNode)
 {
     EpubGuide result = new EpubGuide();
     foreach (XmlNode guideReferenceNode in guideNode.ChildNodes)
         if (String.Compare(guideReferenceNode.LocalName, "reference", StringComparison.OrdinalIgnoreCase) == 0)
         {
             EpubGuideReference guideReference = new EpubGuideReference();
             foreach (XmlAttribute guideReferenceNodeAttribute in guideReferenceNode.Attributes)
             {
                 string attributeValue = guideReferenceNodeAttribute.Value;
                 switch (guideReferenceNodeAttribute.Name.ToLowerInvariant())
                 {
                     case "type":
                         guideReference.Type = attributeValue;
                         break;
                     case "title":
                         guideReference.Title = attributeValue;
                         break;
                     case "href":
                         guideReference.Href = attributeValue;
                         break;
                 }
             }
             if (String.IsNullOrWhiteSpace(guideReference.Type))
                 throw new Exception("Incorrect EPUB guide: item type is missing");
             if (String.IsNullOrWhiteSpace(guideReference.Href))
                 throw new Exception("Incorrect EPUB guide: item href is missing");
             result.Add(guideReference);
         }
     return result;
 }