Example #1
0
        private static EpubGuide ReadGuide(XElement guideNode)
        {
            var result = new EpubGuide();

            foreach (var guideReferenceNode in guideNode.Elements())
            {
                if (string.Compare(guideReferenceNode.Name.LocalName, "reference", StringComparison.OrdinalIgnoreCase) is 0)
                {
                    var guideReference = new EpubGuideReference();
                    foreach (var guideReferenceNodeAttribute in guideReferenceNode.Attributes())
                    {
                        var attributeValue = guideReferenceNodeAttribute.Value;
                        switch (guideReferenceNodeAttribute.Name.LocalName.ToLowerInvariant())
                        {
                        case "type":
                            guideReference.Type = attributeValue;
                            break;

                        case "title":
                            guideReference.Title = attributeValue;
                            break;

                        case "href":
                            guideReference.Href = Uri.UnescapeDataString(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);
        }
Example #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);
        }
        private static EpubGuide ReadGuide(XElement guideNode)
        {
            EpubGuide result = new EpubGuide();

            foreach (XElement guideReferenceNode in guideNode.Elements())
            {
                if (guideReferenceNode.CompareNameTo("reference"))
                {
                    EpubGuideReference guideReference = new EpubGuideReference();
                    foreach (XAttribute guideReferenceNodeAttribute in guideReferenceNode.Attributes())
                    {
                        string attributeValue = guideReferenceNodeAttribute.Value;
                        switch (guideReferenceNodeAttribute.GetLowerCaseLocalName())
                        {
                        case "type":
                            guideReference.Type = attributeValue;
                            break;

                        case "title":
                            guideReference.Title = attributeValue;
                            break;

                        case "href":
                            guideReference.Href = Uri.UnescapeDataString(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);
        }
Example #4
0
        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);
        }
        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;
        }
Example #6
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;
 }