|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- /// <summary>
- /// Returns XML of the Generic Type.
- /// </summary>
- /// <param name="rssDocument">The RSS document.</param>
- /// <typeparam name="T">RssDocumentBase</typeparam>
- /// <returns>string</returns>
- public static string ToRssXml<T>(T rssDocument) where T : RssDocumentBase
- {
- if (rssDocument == null)
- {
- throw new ArgumentNullException("rssDocument");
- }
-
- MemoryStream memoryStream = new MemoryStream();
- String XmlizedString = null;
- using (XmlTextWriter output = new XmlTextWriter(memoryStream, Encoding.UTF8))
- {
-
- XmlSerializer serializer = new XmlSerializer(typeof(T));
- serializer.Serialize(output, rssDocument);
- memoryStream = (MemoryStream)output.BaseStream;
- XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
- return XmlizedString;
- }
- }
-
- /// <summary>
- /// To convert a Byte Array of Unicode values (UTF-8 encoded) to a complete String.
- /// </summary>
- /// <param name="characters">Unicode Byte Array to be converted to String</param>
- /// <returns>String converted from Unicode Byte Array</returns>
- private static String UTF8ByteArrayToString(Byte[] characters)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- String constructedString = encoding.GetString(characters);
- return (constructedString);
- }
|