Esempio n. 1
0
        internal void Load(XElement xLink)
        {
            if (xLink == null)
            {
                throw new ArgumentNullException("xLink");
            }

            if (xLink.Name.LocalName != Fb2InternalLinkElementName)
            {
                throw new ArgumentException("Element of wrong type passed", "xLink");
            }

            LinkText = null;
            //if (xLink.Value != null)
            {
                LinkText = new SimpleText();
                try
                {
                    LinkText.Load(xLink);
                }
                catch (Exception)
                {
                    LinkText = null;
                }
            }

            XAttribute xTypeAttr = xLink.Attribute("type");

            if ((xTypeAttr != null) && (xTypeAttr.Value != null))
            {
                Type = xTypeAttr.Value;
            }

            XAttribute xHRefAttr = xLink.Attribute(lNamespace + "href");

            if ((xHRefAttr != null) && (xHRefAttr.Value != null))
            {
                HRef = xHRefAttr.Value;
            }
        }
Esempio n. 2
0
        internal void Load(XElement xLink)
        {
            if (xLink == null)
            {
                throw new ArgumentNullException("xLink");
            }

            if (xLink.Name.LocalName != Fb2InternalLinkElementName)
            {
                throw new ArgumentException("Element of wrong type passed", "xLink");
            }

            LinkText = null;
            //if (xLink.Value != null)
            {
                LinkText = new SimpleText();
                try
                {
                    LinkText.Load(xLink);
                }
                catch (Exception)
                {
                    LinkText = null;
                }
            }

            XAttribute xTypeAttr = xLink.Attribute("type");
            if ((xTypeAttr != null)&& (xTypeAttr.Value != null))
            {
                Type = xTypeAttr.Value;
            }

            XAttribute xHRefAttr = xLink.Attribute(lNamespace + "href");
            if ((xHRefAttr != null) && (xHRefAttr.Value != null))
            {
                HRef = xHRefAttr.Value;
            }

        }
Esempio n. 3
0
        internal void Load(XElement xLink)
        {
            if (xLink == null)
            {
                throw new ArgumentNullException(nameof(xLink));
            }
            if (xLink.Name.LocalName != Fb2InternalLinkElementName)
            {
                throw new ArgumentException("Element of wrong type passed", nameof(xLink));
            }

            if (xLink.HasElements)
            {
                IEnumerable <XNode> childElements = xLink.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                _linkData.Add(image);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                _linkData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            _linkData.Add(text);
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xLink.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xLink);
                _linkData.Add(text);
            }

            XAttribute xTypeAttr = xLink.Attribute("type");

            if (xTypeAttr != null && xTypeAttr.Value != null)
            {
                Type = xTypeAttr.Value;
            }

            XAttribute xHRefAttr = xLink.Attribute(lNamespace + "href");

            if (xHRefAttr != null && xHRefAttr.Value != null)
            {
                HRef = xHRefAttr.Value;
            }
        }
Esempio n. 4
0
        internal void Load(XElement xSection)
        {
            ClearAll();
            if (xSection == null)
            {
                throw new ArgumentNullException("xSection");
            }

            if (xSection.Name.LocalName != Fb2TextSectionElementName)
            {
                throw new ArgumentException("Element of wrong type passed", "xSection");
            }

            XElement xTitle = xSection.Element(xSection.Name.Namespace + TitleItem.Fb2TitleElementName);
            if (xTitle != null)
            {
                Title = new TitleItem();
                try
                {
                    Title.Load(xTitle);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section title : {0}.", ex.Message));
                }
            }
            
            IEnumerable<XElement> xEpigraphs =
                xSection.Elements(xSection.Name.Namespace + EpigraphItem.Fb2EpigraphElementName);
            foreach (var xEpigraph in xEpigraphs)
            {
                EpigraphItem epigraph = new EpigraphItem();
                try
                {
                    epigraph.Load(xEpigraph);
                    _epigraphs.Add(epigraph);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section epigraph : {0}.", ex.Message));
                }
            }

            XElement xAnnotation = xSection.Element(xSection.Name.Namespace + AnnotationItem.Fb2AnnotationItemName);
            if (xAnnotation != null)
            {
                Annotation  = new AnnotationItem();
                try
                {
                    Annotation.Load(xAnnotation);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section annotation : {0}.", ex.Message));
                }
            }

            IEnumerable<XElement> xElements = xSection.Elements();
            foreach (var xElement in xElements)
            {
                switch (xElement.Name.LocalName)
                {
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(xElement);
                            _content.Add(paragraph);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section paragraph : {0}.", ex.Message));
                        }
                        break;
                    case PoemItem.Fb2PoemElementName:
                        PoemItem poem = new PoemItem();
                        try
                        {
                            poem.Load(xElement);
                            _content.Add(poem);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section poem : {0}.", ex.Message));
                        }
                        break;
                    case ImageItem.Fb2ImageElementName:
                        ImageItem image = new ImageItem();
                        try
                        {
                            image.Load(xElement);
                            AddImage(image);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section image : {0}.", ex.Message));
                        }
                        break;
                    case SubTitleItem.Fb2SubtitleElementName:
                        SubTitleItem subtitle = new SubTitleItem();
                        try
                        {
                            subtitle.Load(xElement);
                            _content.Add(subtitle);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section subtitle : {0}.", ex.Message));
                        }
                        break;
                    case CiteItem.Fb2CiteElementName:
                        CiteItem cite = new CiteItem();
                        try
                        {
                            cite.Load(xElement);
                            _content.Add(cite);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section citation : {0}.", ex.Message));
                        }
                        break;
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        EmptyLineItem eline = new EmptyLineItem();
                        _content.Add(eline);
                        break;
                    case TableItem.Fb2TableElementName:
                        TableItem table = new TableItem();
                        try
                        {
                            table.Load(xElement);
                            _content.Add(table);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section emptly line : {0}.", ex.Message));
                        }
                        break;
                    case Fb2TextSectionElementName: // internal <section> read recurive
                        SectionItem section = new SectionItem();
                        try
                        {
                            section.Load(xElement);
                            AddSection(section);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load sub-section : {0}.", ex.Message));
                        }
                        break;
                    case AnnotationItem.Fb2AnnotationItemName: // already processed
                        break; 
                    case TitleItem.Fb2TitleElementName: // already processed
                        break;
                    case EpigraphItem.Fb2EpigraphElementName: // already processed
                        break;
                    default:
                        if (!string.IsNullOrEmpty(xElement.Value))
                        {
                            ParagraphItem tempParagraph = new ParagraphItem();
                            try
                            {
                                SimpleText text = new SimpleText {Text = xElement.Value};
                                tempParagraph.ParagraphData.Add(text);
                                _content.Add(tempParagraph);
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                        Debug.WriteLine("AnnotationItem:Load - invalid element <{0}> encountered in title .", xElement.Name.LocalName);
                        break;
                }
            }

            ID = null;
            XAttribute xID = xSection.Attribute("id");
            if ((xID != null))
            {
                ID = xID.Value;
            }

            Lang = null;
            XAttribute xLang = xSection.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null))
            {
                Lang = xLang.Value;
            }
        }
        /// <summary>
        /// Create a text with Capital Drop
        /// </summary>
        /// <param name="parent">parent container insert into</param>
        /// <param name="text">text to insert</param>
        private void AddAsDrop(List<IHTMLItem> parent, SimpleText text)
        {
            var span1 = new Span(HTMLElementType.XHTML11);
            SetClassType(span1, ElementStylesV2.CapitalDrop);
            int dropEnd = 0;
            // "pad" the white spaces so drop starts from visible character
            while (dropEnd < text.Text.Length && UnicodeHelpers.IsSpaceLike(text.Text[dropEnd]) )
            {
                dropEnd++;
            }
            if (dropEnd >= text.Text.Length) // in case the text is too short for drop
            {
                parent.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text });
                return;
            }
            // calculate the initial drop part
            string dropPart = text.Text.Substring(0, dropEnd + 1);
            // non-drop part starts from the next character
            int nondropPosition = dropEnd + 1;
            // If first character is dash/hyphen like we need to add character to 
            // capital drop so it looks better with next character
            if (UnicodeHelpers.IsNeedToBeJoinInDrop(dropPart[dropEnd]))
            {
                // we need to add to capital drop all spaces if any
                while (nondropPosition < text.Text.Length && UnicodeHelpers.IsSpaceLike(text.Text[nondropPosition]))
                {
                    nondropPosition++;
                }
                // we need to advance to include one following nonspace character , unless
                // we already at last character of the text
                if (nondropPosition < text.Text.Length)
                {
                    nondropPosition++;
                }
                // update drop part with the "string" we calculated
                dropPart += text.Text.Substring(dropEnd + 1, nondropPosition - dropEnd - 1);
            }
            span1.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = dropPart });
            parent.Add(span1);
            string substring = text.Text.Substring(nondropPosition);
            if (substring.Length > 0)
            {
                parent.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = substring });
            }

        }
Esempio n. 6
0
 public void Load(XNode xText)
 {
     subtext.Clear();
     if (xText == null)
     {
         throw new ArgumentNullException("xText");
     }
     switch (xText.NodeType)
     {
         case XmlNodeType.Text:
             XText textNode = (XText) xText;
             if (!string.IsNullOrEmpty(textNode.Value))
             {
                 Text = textNode.Value;
                 style = TextStyles.Normal;
             }
             break;
         case XmlNodeType.Element:
             XElement xTextElement = (XElement)xText;
             if (xTextElement.HasElements)
             {
                 Text = string.Empty;
                 style = GetStyle(xTextElement.Name.LocalName);
                 IEnumerable<XNode> childElements = xTextElement.Nodes();
                 foreach (var node in childElements)
                 {
                     if (node.NodeType == XmlNodeType.Element)
                     {
                         XElement element = (XElement) node;
                         switch (element.Name.LocalName)
                         {
                             case InternalLinkItem.Fb2InternalLinkElementName:
                                 InternalLinkItem link = new InternalLinkItem();
                                 try
                                 {
                                     link.Load(element);
                                     subtext.Add(link);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             case InlineImageItem.Fb2InlineImageElementName:
                                 InlineImageItem image = new InlineImageItem();
                                 try
                                 {
                                     image.Load(element);
                                     subtext.Add(image);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             default:
                                 SimpleText text = new SimpleText();
                                 try
                                 {
                                     text.Load(element);
                                     subtext.Add(text);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                         }
                     }
                     else
                     {
                         SimpleText text = new SimpleText();
                         try
                         {
                             text.Load(node);
                             subtext.Add(text);
                         }
                         catch (Exception)
                         {
                             continue;
                         }
                     }
                 }
             }
             else
             {
                 style = GetStyle(xTextElement.Name.LocalName);
                 Text = xTextElement.Value;
                 //switch (xTextElement.Name.LocalName)
                 //{
                 //    case "strong":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "emphasis":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "code":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sub":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sup":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "strikethrough":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    default:
                 //        Text = xTextElement.Value;
                 //        break;
                 //}
             }
             break;
     }
 }
Esempio n. 7
0
        internal void Load(XElement xSection)
        {
            ClearAll();
            if (xSection == null)
            {
                throw new ArgumentNullException("xSection");
            }

            if (xSection.Name.LocalName != Fb2TextSectionElementName)
            {
                throw new ArgumentException("Element of wrong type passed", "xSection");
            }

            XElement xTitle = xSection.Element(xSection.Name.Namespace + TitleItem.Fb2TitleElementName);

            if (xTitle != null)
            {
                Title = new TitleItem();
                try
                {
                    Title.Load(xTitle);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section title : {0}.", ex.Message));
                }
            }

            IEnumerable <XElement> xEpigraphs =
                xSection.Elements(xSection.Name.Namespace + EpigraphItem.Fb2EpigraphElementName);

            foreach (var xEpigraph in xEpigraphs)
            {
                EpigraphItem epigraph = new EpigraphItem();
                try
                {
                    epigraph.Load(xEpigraph);
                    _epigraphs.Add(epigraph);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section epigraph : {0}.", ex.Message));
                }
            }

            XElement xAnnotation = xSection.Element(xSection.Name.Namespace + AnnotationItem.Fb2AnnotationItemName);

            if (xAnnotation != null)
            {
                Annotation = new AnnotationItem();
                try
                {
                    Annotation.Load(xAnnotation);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section annotation : {0}.", ex.Message));
                }
            }

            IEnumerable <XElement> xElements = xSection.Elements();

            foreach (var xElement in xElements)
            {
                switch (xElement.Name.LocalName)
                {
                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(xElement);
                        _content.Add(paragraph);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section paragraph : {0}.", ex.Message));
                    }
                    break;

                case PoemItem.Fb2PoemElementName:
                    PoemItem poem = new PoemItem();
                    try
                    {
                        poem.Load(xElement);
                        _content.Add(poem);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section poem : {0}.", ex.Message));
                    }
                    break;

                case ImageItem.Fb2ImageElementName:
                    ImageItem image = new ImageItem();
                    try
                    {
                        image.Load(xElement);
                        AddImage(image);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section image : {0}.", ex.Message));
                    }
                    break;

                case SubTitleItem.Fb2SubtitleElementName:
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(xElement);
                        _content.Add(subtitle);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section subtitle : {0}.", ex.Message));
                    }
                    break;

                case CiteItem.Fb2CiteElementName:
                    CiteItem cite = new CiteItem();
                    try
                    {
                        cite.Load(xElement);
                        _content.Add(cite);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section citation : {0}.", ex.Message));
                    }
                    break;

                case EmptyLineItem.Fb2EmptyLineElementName:
                    EmptyLineItem eline = new EmptyLineItem();
                    _content.Add(eline);
                    break;

                case TableItem.Fb2TableElementName:
                    TableItem table = new TableItem();
                    try
                    {
                        table.Load(xElement);
                        _content.Add(table);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section emptly line : {0}.", ex.Message));
                    }
                    break;

                case Fb2TextSectionElementName:     // internal <section> read recurive
                    SectionItem section = new SectionItem();
                    try
                    {
                        section.Load(xElement);
                        AddSection(section);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load sub-section : {0}.", ex.Message));
                    }
                    break;

                case AnnotationItem.Fb2AnnotationItemName:     // already processed
                    break;

                case TitleItem.Fb2TitleElementName:     // already processed
                    break;

                case EpigraphItem.Fb2EpigraphElementName:     // already processed
                    break;

                default:
                    if (!string.IsNullOrEmpty(xElement.Value))
                    {
                        ParagraphItem tempParagraph = new ParagraphItem();
                        try
                        {
                            SimpleText text = new SimpleText {
                                Text = xElement.Value
                            };
                            tempParagraph.ParagraphData.Add(text);
                            _content.Add(tempParagraph);
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    Debug.Print("AnnotationItem:Load - invalid element <{0}> encountered in title .", xElement.Name.LocalName);
                    break;
                }
            }

            ID = null;
            XAttribute xID = xSection.Attribute("id");

            if ((xID != null))
            {
                ID = xID.Value;
            }

            Lang = null;
            XAttribute xLang = xSection.Attribute(XNamespace.Xml + "lang");

            if ((xLang != null))
            {
                Lang = xLang.Value;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Load element data from the node
        /// </summary>
        /// <param name="xStyle"></param>
        public void Load(XElement xStyle)
        {
            if (xStyle == null)
            {
                throw new ArgumentNullException("style");
            }
            if (xStyle.Name.LocalName != StyleItemName)
            {
                throw new ArgumentException(string.Format("The element is of type {0} while StyleItem accepts only {1} types", xStyle.Name.LocalName, StyleItemName));
            }

            Lang = null;
            XAttribute xLang = xStyle.Attribute(XNamespace.Xml + "lang");

            if (xLang != null)
            {
                Lang = xLang.Value;
            }

            Name = string.Empty;
            XAttribute xName = xStyle.Attribute("name");

            if (xName != null && xName.Value != null)
            {
                Name = xName.Value;
            }

            if (xStyle.HasElements)
            {
                IEnumerable <XNode> childElements = xStyle.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                StyleData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                StyleData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                StyleData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            StyleData.Add(text);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xStyle.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xStyle);
                StyleData.Add(text);
            }
        }
Esempio n. 9
0
        public void Load(XNode xText)
        {
            subtext.Clear();
            if (xText == null)
            {
                throw new ArgumentNullException("xText");
            }
            switch (xText.NodeType)
            {
            case XmlNodeType.Text:
                XText textNode = (XText)xText;
                if (!string.IsNullOrEmpty(textNode.Value))
                {
                    Text  = textNode.Value;
                    style = TextStyles.Normal;
                }
                break;

            case XmlNodeType.Element:
                XElement xTextElement = (XElement)xText;
                if (xTextElement.HasElements)
                {
                    Text  = string.Empty;
                    style = GetStyle(xTextElement.Name.LocalName);
                    IEnumerable <XNode> childElements = xTextElement.Nodes();
                    foreach (var node in childElements)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            XElement element = (XElement)node;
                            switch (element.Name.LocalName)
                            {
                            case InternalLinkItem.Fb2InternalLinkElementName:
                                InternalLinkItem link = new InternalLinkItem();
                                try
                                {
                                    link.Load(element);
                                    subtext.Add(link);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            case InlineImageItem.Fb2InlineImageElementName:
                                InlineImageItem image = new InlineImageItem();
                                try
                                {
                                    image.Load(element);
                                    subtext.Add(image);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            default:
                                SimpleText text = new SimpleText();
                                try
                                {
                                    text.Load(element);
                                    subtext.Add(text);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;
                            }
                        }
                        else
                        {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(node);
                                subtext.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    style = GetStyle(xTextElement.Name.LocalName);
                    Text  = xTextElement.Value;
                    //switch (xTextElement.Name.LocalName)
                    //{
                    //    case "strong":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "emphasis":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "code":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sub":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sup":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "strikethrough":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    default:
                    //        Text = xTextElement.Value;
                    //        break;
                    //}
                }
                break;
            }
        }
Esempio n. 10
0
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable <XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                paragraphData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            paragraphData.Add(text);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");

            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");

            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
        }
Esempio n. 11
0
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable<XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement) element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);

                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);

                            }
                            catch (Exception)
                            {
                            }                            
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(element);
                                paragraphData.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                    }
                }
               
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");
            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");
            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
            
        }