<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:snippet="http://codexchange.org/schemas/snippet/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>CodeXchange: User Contributed Snippets</title>
    <link>http://www.codexchange.org</link>
    <description>Summary of the snippets published by a codexchange user</description>
    <language>en-us</language>
    <copyright>Copyright © CodeXchange, 2004-2006</copyright>
    <generator>CodeXchange RSS Feed Generator v1.0</generator>
    <webMaster>webmaster@codexchange.org</webMaster>
    <lastBuildDate>Thu, 15 Oct 2026 10:29:50 GMT</lastBuildDate>
    <ttl>20</ttl>
    <dc:language>en-us</dc:language>
    <dc:rights>Copyright © CodeXchange, 2004-2006</dc:rights>
    <dc:date>10/15/2026 10:29:50 AM</dc:date>
    <dc:publisher />
    <dc:creator>CodeXchange RSS Feed Generator v1.0</dc:creator>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=26b31560-2a78-42a6-91cb-1c6599174612</guid>
      <title>Reformats a given xml document using rules.</title>
      <link>/PreviewSnippet.aspx?SnippetID=26b31560-2a78-42a6-91cb-1c6599174612</link>
      <description>Reformats a given xml document using rules. [C#]</description>
      <author>Jan Zieschang</author>
      <pubDate>Sat, 03 Sep 2005 17:07:59 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=26b31560-2a78-42a6-91cb-1c6599174612#comments</comments>
      <category>e5dc5661-427e-4d33-8be6-187bd2783223</category>
      <dc:title>Reformats a given xml document using rules.</dc:title>
      <dc:date>9/3/2005 5:07:59 PM</dc:date>
      <dc:creator>Jan Zieschang</dc:creator>
      <content:encoded><![CDATA[<pre>        /// <summary>
        /// Formats the XML document using the given rules.
        /// </summary>
        /// <param name="xtw">The document to format</param>
        /// <param name="removeComments"><see langword="true"/> if comments should be removed from document; otherwise, <see langword="false"/>.(Processing instructions will also be removed if, <see language="true"/>)</param>
        /// <param name="format">The formatting option.</param>
        /// <param name="indentationChars">Number of characters to indent the next level in document.</param>
        /// <param name="insertBlankLine"><see langword="true"/> if if a blank line should be inserted after each element definition; otherwise, <see langword="false"/>.</param>
        /// <returns>The newly formated document</returns>
        public static string FormatXmlDocument(XmlTextReader xtw, bool removeComments, Formatting format, int indentationChars, bool insertBlankLine)
        {
            if(xtw == null)
                throw new ArgumentNullException("xtw");
            if(xtw.ReadState == ReadState.Closed  || xtw.ReadState == ReadState.EndOfFile || xtw.ReadState == ReadState.Error)
            {
                throw new ArgumentOutOfRangeException("xtw");
            }
            if(indentationChars < 0)
                throw new ArgumentOutOfRangeException("indentationChars", indentationChars, "The number of chars must be greater or equal to zero!");
            StringBuilder builder1 = new StringBuilder(5000);
            XmlTextWriter writer1 = new XmlTextWriter(new StringWriter(builder1));
            XmlTextReader reader1 = xtw;
            try
            {
                bool flag1 = false;
                writer1.Formatting = format;
                writer1.Indentation = indentationChars;
                reader1.WhitespaceHandling = WhitespaceHandling.None;
                while (reader1.Read())
                {
                    switch (reader1.NodeType)
                    {
                        case XmlNodeType.Attribute:
                            writer1.WriteAttributeString(reader1.Prefix, reader1.LocalName, reader1.NamespaceURI, reader1.Value);
                            break;
                        case XmlNodeType.Text:
                            writer1.WriteString(reader1.Value);
                            break;
                        case XmlNodeType.CDATA:
                            writer1.WriteCData(reader1.Value);
                            break;
                        case XmlNodeType.EntityReference:
                            writer1.WriteEntityRef(reader1.Name);
                            break;
                        case XmlNodeType.Element:
                            flag1 = reader1.IsEmptyElement;
                            writer1.WriteStartElement(reader1.Prefix, reader1.LocalName, reader1.NamespaceURI);
                            if (reader1.HasAttributes)
                            {
                                reader1.MoveToFirstAttribute();
                                do
                                {
                                    writer1.WriteAttributeString(reader1.Prefix, reader1.LocalName, reader1.NamespaceURI, reader1.Value);
                                }
                                while (reader1.MoveToNextAttribute());
                            }
                            if (flag1)
                            {
                                writer1.WriteEndElement();
                            }
                            break;
                        case XmlNodeType.ProcessingInstruction:
                            if (!removeComments)
                                writer1.WriteProcessingInstruction(reader1.Name, reader1.Value);
                            break;
                        case XmlNodeType.Comment:
                            if (!removeComments)
                                writer1.WriteComment(reader1.Value);
                            break;
                        case XmlNodeType.Document:
                            writer1.WriteStartElement(reader1.Prefix, reader1.LocalName, reader1.NamespaceURI);
                            break;
                        case XmlNodeType.DocumentType:
                            writer1.WriteDocType(reader1.Name, "", "", "");
                            break;
                        case XmlNodeType.EndElement:
                            writer1.WriteEndElement();
                            if(insertBlankLine)
                                writer1.WriteWhitespace(Environment.NewLine);
                            break;
                        case XmlNodeType.XmlDeclaration:
                            writer1.WriteStartDocument();
                            break;
                        default:
                            break;
                    }
                }
            }
            finally
            {
                if ((writer1 != null) && (writer1.WriteState != WriteState.Closed))
                    writer1.Close();
            }
            return builder1.ToString();
        }</pre>]]></content:encoded>
      <snippet:downloads>3</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=cacfd5c3-04ee-4d9e-bde8-322765dd74f9</guid>
      <title>Expand/Increase size of an array</title>
      <link>/PreviewSnippet.aspx?SnippetID=cacfd5c3-04ee-4d9e-bde8-322765dd74f9</link>
      <description>Expand/Increase size of an array [C#]</description>
      <author>Jan Zieschang</author>
      <pubDate>Sat, 15 Oct 2005 11:35:08 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=cacfd5c3-04ee-4d9e-bde8-322765dd74f9#comments</comments>
      <category>f8b47dd5-9f0a-4831-b7ad-ae8d5083baf3</category>
      <dc:title>Expand/Increase size of an array</dc:title>
      <dc:date>10/15/2005 11:35:08 AM</dc:date>
      <dc:creator>Jan Zieschang</dc:creator>
      <content:encoded><![CDATA[<pre>		/// <summary>
		/// Expands the array by the given size.
		/// </summary>
		/// <param name="array">the source array. <see langword="null"/> can be null. All values will be copied to the new array.</param>
		/// <param name="size">Increment size of the new array</param>
		/// <param name="arrayItemType">types of the new array</param>
		/// <returns></returns>
		/// <exception cref="ArgumentNullException">if arrayItemType parameter is null.</exception>
		/// <exception cref="ArgumentOutOfRangeException">if size parameter is less or equal to zero</exception>
		/// <exception cref="FormatException">if type of source array is not convertable to arrayItemType</exception>
		public static Array ExpandArray(Array array, int size, Type arrayItemType)
		{
			if(arrayItemType == null)
				throw new ArgumentNullException("arrayItemType");
			if(size <= 0)
				throw new ArgumentOutOfRangeException("size", size, "Size must be greater then 0!");
			Array me = Array.CreateInstance(arrayItemType, array == null ? size : array.Length + size);
			if(array != null && array.Length > 0)
			{
				for(int i = 0; i < array.Length; i++)
				{
					object val = array.GetValue(i);
					me.SetValue(Convert.ChangeType(val, arrayItemType) , i);
				}
			}
			return me;
		}
</pre>]]></content:encoded>
      <snippet:downloads>0</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
  </channel>
</rss>