/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="xe"></param> internal void SerializeToXml(AtomVersion version, XmlElement xe) { if (version == AtomVersion.Atom_1_0) { if (this.Name != null) { XmlElement xeName = xe.OwnerDocument.CreateElement(XMLTAG_NAME); xeName.InnerText = this.Name; xe.AppendChild(xeName); } if (this.Uri != null) { XmlElement xeUri = xe.OwnerDocument.CreateElement(XMLTAG_URI); xeUri.InnerText = this.Uri; xe.AppendChild(xeUri); } if (this.Email != null) { XmlElement xeEmail = xe.OwnerDocument.CreateElement(XMLTAG_EMAIL); xeEmail.InnerText = this.Email; xe.AppendChild(xeEmail); } // // Always serialize modules last. // if (this.Modules != null) { this.Modules.SerializeToXml(xe); } } }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="validateContent"></param> public void Validate(AtomVersion version, bool validateContent) { foreach (AtomCategory category in this) { category.Validate(version, validateContent); } }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="validateContent"></param> public void Validate(AtomVersion version, bool validateContent) { foreach (AtomAuthor author in this) { author.Validate(version, validateContent); } }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="validateContent"></param> public void Validate(AtomVersion version, bool validateContent) { foreach (AtomContributor contributor in this) { contributor.Validate(version, validateContent); } }
/// <summary> /// Deserializes the object from XML. /// </summary> /// <param name="xdRss"></param> private void DeserializeFromXml(XmlDocument xdAtom) { // // Set default values. // this.m_recognizedVersion = AtomVersion.Unknown; this.NamespaceUri = null; // // Load document element. // XmlNode xnAtom = xdAtom.DocumentElement; // // Check that we have ATOM local name. // if (xnAtom.LocalName != XMLELEMENT_FEED) { throw new SyndicationFormatInvalidException(Atom.ATOM_ERRORMESSAGE_INVALID_ATOM_FORMAT_1_0); } // // Version 1.0 // this.NamespaceUri = xnAtom.NamespaceURI; if (xnAtom.NamespaceURI == ATOM_ATTRIBUTE_XMLNS_VALUE_1_0) { this.m_recognizedVersion = AtomVersion.Atom_1_0; } // // Deserialize from XML. // DeserializeFromXml(xnAtom); }
/// <summary> /// Serializes the class to XML. /// </summary> /// <param name="version"></param> /// <param name="xdAtom"></param> /// <returns></returns> internal XmlNode SerializeToXml(AtomVersion version, XmlDocument xdAtom) { if (version == AtomVersion.Atom_1_0) { return(SerializeToXml_1_0(xdAtom)); } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_CANNOT_SERIALIZE_UNRECOGNIZED_VERSION); }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="validateContent"></param> public void Validate(AtomVersion version, bool validateContent) { if (version == AtomVersion.Atom_1_0) { ValidateAtom_1_0(validateContent); return; } throw new SyndicationValidationException(Atom.ATOM_ERRORMESSAGE_CANNOT_VALIDATE_UNRECOGNIZED_VERSION); }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="validateContent"></param> public void Validate(AtomVersion version, bool validateContent) { if (version == AtomVersion.Atom_1_0) { ValidateAtom_1_0(validateContent); return; } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_UNKNOWN_VALUE, "version"); }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="xdAtom"></param> /// <returns></returns> internal List <XmlNode> SerializeToXml(AtomVersion version, XmlDocument xdAtom) { List <XmlNode> nodes = new List <XmlNode>(); foreach (AtomContributor contributor in this) { nodes.Add(contributor.SerializeToXml(version, xdAtom)); } return(nodes); }
/// <summary> /// Serializes the collection. /// </summary> /// <param name="version"></param> /// <param name="xdAtom"></param> /// <returns></returns> internal List <XmlNode> SerializeToXml(AtomVersion version, XmlDocument xdAtom) { List <XmlNode> nodes = new List <XmlNode>(); foreach (AtomEntry entry in this) { nodes.Add(entry.SerializeToXml(version, xdAtom)); } return(nodes); }
/// <summary> /// Save the ATOM object to XML. /// </summary> /// <param name="version"></param> /// <param name="encoding"></param> /// <param name="version"></param> /// <returns></returns> public XmlDocument Save(AtomVersion version) { if (version == AtomVersion.Atom_1_0) { if (ValidateOnSave) { Validate(version, this.ValidateContent); } return(SerializeToXml_1_0(DEFAULT_ENCODING)); } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_CANNOT_SAVE_UNRECOGNIZED_VERSION); }
/// <summary> /// Save the ATOM object to XML. /// </summary> /// <param name="version"></param> /// <param name="encoding"></param> /// <param name="version"></param> /// <returns></returns> public XmlDocument Save(AtomVersion version, string encoding) { if (encoding == null) { throw new ArgumentNullException("encoding"); } if (version == AtomVersion.Atom_1_0) { if (ValidateOnSave) { Validate(version, this.ValidateContent); } return(SerializeToXml_1_0(encoding)); } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_CANNOT_SAVE_UNRECOGNIZED_VERSION); }
/// <summary> /// Saves the ATOM object according to the version and encoding arguments. /// </summary> /// <param name="filename"></param> /// <param name="version"></param> /// <param name="encoding"></param> /// <param name="customVersion"></param> public void Save(string filename, AtomVersion version, string encoding) { if (filename == null) { throw new ArgumentNullException("filename"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (version == AtomVersion.Atom_1_0) { this.Save(version, encoding).Save(filename); return; } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_CANNOT_SAVE_UNRECOGNIZED_VERSION); }
/// <summary> /// Saves the ATOM object according to the version and encoding arguments. /// </summary> /// <param name="stream"></param> /// <param name="version"></param> /// <param name="encoding"></param> /// <returns></returns> public void Save(System.IO.Stream stream, AtomVersion version, string encoding) { if (stream == null) { throw new ArgumentNullException("stream"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (version == AtomVersion.Atom_1_0) { this.Save(version, encoding).Save(stream); return; } throw new ArgumentException(Atom.ATOM_ERRORMESSAGE_CANNOT_SAVE_UNRECOGNIZED_VERSION); }
/// <summary> /// Validates that the object model has the elements it needs /// to produce an ATOM XML of the desired version. /// </summary> /// <param name="version"></param> public bool Validate(AtomVersion version, bool validateContent) { if (version == AtomVersion.Atom_1_0) { // // Check for required elements. // if (this.Id == null) { string msg = string.Format(Atom.ATOM_ERRORMESSAGE_VALIDATION_REQUIRED_FIELD_NULL, "Id"); throw new SyndicationValidationException(msg); } if (this.Title == null) { string msg = string.Format(Atom.ATOM_ERRORMESSAGE_VALIDATION_REQUIRED_FIELD_NULL, "Title"); throw new SyndicationValidationException(msg); } if (this.Updated == null) { string msg = string.Format(Atom.ATOM_ERRORMESSAGE_VALIDATION_REQUIRED_FIELD_NULL, "Updated"); throw new SyndicationValidationException(msg); } // // Ask each item to validate itself. // if (this.Authors != null) { this.Authors.Validate(version, validateContent); } if (this.Categories != null) { this.Categories.Validate(version, validateContent); } if (this.Contributors != null) { this.Contributors.Validate(version, validateContent); } if (this.Entries != null) { this.Entries.Validate(version, validateContent); } if (this.Generator != null) { this.Generator.Validate(version, validateContent); } //if (this.Icon != null) //{ //} //if (this.Id != null) //{ //} if (this.Links != null) { this.Links.Validate(version, validateContent); } if (this.Rights != null) { this.Rights.Validate(version, validateContent); } if (this.Subtitle != null) { this.Subtitle.Validate(version, validateContent); } if (this.Title != null) { this.Title.Validate(version, validateContent); } //if (this.Updated != null) //{ //} return(true); } throw new SyndicationValidationException(Atom.ATOM_ERRORMESSAGE_CANNOT_VALIDATE_UNRECOGNIZED_VERSION); }
/// <summary> /// Deserializes the object from XML. /// </summary> /// <param name="xnRss"></param> private void DeserializeFromXml(XmlNode xnFeed) { // // Try-Catch block to make sure the version is set back to NotSet if the deserialization fails. // try { // // Set namespace manager. // XmlNamespaceManager nsmgr = new XmlNamespaceManager(xnFeed.OwnerDocument.NameTable); nsmgr.AddNamespace(NAMESPACE_PREFIX_XMLNS, this.NamespaceUri); // // Author. // XmlNodeList xnlAuthors = xnFeed.SelectNodes(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomAuthor.XML_TAG), nsmgr); if (xnlAuthors != null) { this.Authors = new AtomAuthorCollection(xnlAuthors); } // // Category. // XmlNodeList xnlCategories = xnFeed.SelectNodes(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomCategory.XML_TAG), nsmgr); if (xnlCategories != null) { this.Categories = new AtomCategoryCollection(xnlCategories); } // // Contributor. // XmlNodeList xnlContributors = xnFeed.SelectNodes(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomContributor.XML_TAG), nsmgr); if (xnlContributors != null) { this.Contributors = new AtomContributorCollection(xnlContributors); } // // Generator. // XmlNode xnGenerator = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomGenerator.XML_TAG), nsmgr); if (xnGenerator != null) { this.Generator = new AtomGenerator(xnGenerator); } // // Icon. // XmlNode xnIcon = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_ICON), nsmgr); if (xnIcon != null) { this.Icon = xnIcon.InnerText; } // // Id. // XmlNode xnId = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_ID), nsmgr); if (xnId != null) { this.Id = xnId.InnerText; } // // Link. // XmlNodeList xnlLink = xnFeed.SelectNodes(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomLink.XML_TAG), nsmgr); if (xnlLink != null) { this.Links = new AtomLinkCollection(xnlLink); } // // Logo. // XmlNode xnLogo = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_LOGO), nsmgr); if (xnLogo != null) { this.Logo = xnLogo.InnerText; } // // Rights. // XmlNode xnRights = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_RIGHTS), nsmgr); if (xnRights != null) { this.Rights = new AtomText(xnRights); } // // Subtitle. // XmlNode xnSubtitle = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_SUBTITLE), nsmgr); if (xnSubtitle != null) { this.Subtitle = new AtomText(xnSubtitle); } // // Title. // XmlNode xnTitle = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_TITLE), nsmgr); if (xnTitle != null) { this.Title = new AtomText(xnTitle); } // // Updated. // XmlNode xnUpdated = xnFeed.SelectSingleNode(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, XMLELEMENT_UPDATED), nsmgr); if (xnUpdated != null) { this.Updated = new AtomDateTime(xnUpdated.InnerText); } // // Entries. // XmlNodeList xnlEntries = xnFeed.SelectNodes(string.Format("{0}:{1}", NAMESPACE_PREFIX_XMLNS, AtomEntry.XML_TAG), nsmgr); if (xnlEntries != null) { this.Entries = new AtomEntryCollection(xnlEntries); } // // Deserialize Modules. // List <SyndicationModuleExclusionElement> exclusionElements = new List <SyndicationModuleExclusionElement>(); //exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_FEED, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomAuthor.XML_TAG, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomCategory.XML_TAG, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomContributor.XML_TAG, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomGenerator.XML_TAG, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_ICON, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_ID, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomLink.XML_TAG, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_LOGO, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_RIGHTS, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_SUBTITLE, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_TITLE, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(XMLELEMENT_UPDATED, this.NamespaceUri)); exclusionElements.Add(new SyndicationModuleExclusionElement(AtomEntry.XML_TAG, this.NamespaceUri)); this.Modules = new SyndicationModuleCollection(xnFeed, exclusionElements); } catch (OutOfMemoryException) { throw; } catch (StackOverflowException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception) { this.m_recognizedVersion = AtomVersion.NotSet; throw; } }
internal void SerializeToXml(AtomVersion version, XmlElement xe) { if (version == AtomVersion.Atom_1_0) { switch (this.Type) { case AtomTextType.NotSet: { if (this.Text != null) { xe.InnerText = this.Text; } break; } case AtomTextType.Html: { if (this.Text != null) { xe.InnerText = this.Text; } XmlAttribute xaType = xe.OwnerDocument.CreateAttribute("type"); xaType.InnerText = "html"; xe.Attributes.Append(xaType); break; } case AtomTextType.Text: { if (this.Text != null) { xe.InnerText = this.Text; } XmlAttribute xaType = xe.OwnerDocument.CreateAttribute("type"); xaType.InnerText = "text"; xe.Attributes.Append(xaType); break; } case AtomTextType.XHtml: { if (this.Text != null) { xe.InnerXml = this.Text; } XmlAttribute xaType = xe.OwnerDocument.CreateAttribute("type"); xaType.InnerText = "xhtml"; xe.Attributes.Append(xaType); break; } default: { string msg = string.Format(Atom.ATOM_ERRORMESSAGE_SERIALIZATION_ILLEGAL_VALUE, "AtomTextType", xe.Name); throw new SyndicationSerializationException(msg); } } ; // // Always serialize modules last. // if (this.Modules != null) { this.Modules.SerializeToXml(xe); } } }