Esempio n. 1
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. 2
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. 3
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;
            }
        }