/// <summary> /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute); if (type != AtomTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (this.TextType == AtomTextConstructType.Xhtml) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { this.Content = xhtmlDivNavigator.Value; wasLoaded = true; } } else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml)) { this.Content = source.InnerXml; wasLoaded = true; } else if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute); if (type != AtomTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (this.TextType == AtomTextConstructType.Xhtml) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { this.Content = xhtmlDivNavigator.Value; wasLoaded = true; } } else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml)) { this.Content = source.InnerXml; wasLoaded = true; } else if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }