コード例 #1
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxNavigationTarget ReadNavigationTarget(XElement navigationTargetNode)
        {
            Epub2NcxNavigationTarget result = new Epub2NcxNavigationTarget();

            foreach (XAttribute navigationPageTargetNodeAttribute in navigationTargetNode.Attributes())
            {
                string attributeValue = navigationPageTargetNodeAttribute.Value;
                switch (navigationPageTargetNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "value":
                    result.Value = attributeValue;
                    break;

                case "class":
                    result.Class = attributeValue;
                    break;

                case "playorder":
                    result.PlayOrder = attributeValue;
                    break;
                }
            }
            if (String.IsNullOrWhiteSpace(result.Id))
            {
                throw new Exception("Incorrect EPUB navigation target: navigation target ID is missing.");
            }
            foreach (XElement navigationTargetChildNode in navigationTargetNode.Elements())
            {
                switch (navigationTargetChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationTargetChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "content":
                    Epub2NcxContent content = ReadNavigationContent(navigationTargetChildNode);
                    result.Content = content;
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception("Incorrect EPUB navigation target: at least one navLabel element is required.");
            }
            return(result);
        }
コード例 #2
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxNavigationList ReadNavigationList(XElement navigationListNode)
        {
            Epub2NcxNavigationList result = new Epub2NcxNavigationList();

            foreach (XAttribute navigationListNodeAttribute in navigationListNode.Attributes())
            {
                string attributeValue = navigationListNodeAttribute.Value;
                switch (navigationListNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "class":
                    result.Class = attributeValue;
                    break;
                }
            }
            foreach (XElement navigationListChildNode in navigationListNode.Elements())
            {
                switch (navigationListChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationListChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "navTarget":
                    Epub2NcxNavigationTarget navigationTarget = ReadNavigationTarget(navigationListChildNode);
                    result.NavigationTargets.Add(navigationTarget);
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required.");
            }
            return(result);
        }