public static void XmlReaderClone(System.Xml.XmlReader reader, System.Xml.XmlWriter writer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("System.Xml.XmlReader");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("System.Xml.XmlWriter");
            }

            switch (reader.NodeType)
            {
            case System.Xml.XmlNodeType.Element:

                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);

                writer.WriteAttributes(reader, true);

                if (reader.IsEmptyElement)
                {
                    writer.WriteEndElement();
                }

                break;

            case System.Xml.XmlNodeType.Text:

                writer.WriteString(reader.Value);

                break;

            case System.Xml.XmlNodeType.Whitespace:

            case System.Xml.XmlNodeType.SignificantWhitespace:

                writer.WriteWhitespace(reader.Value);

                break;

            case System.Xml.XmlNodeType.CDATA:

                writer.WriteCData(reader.Value);

                break;

            case System.Xml.XmlNodeType.EntityReference:

                writer.WriteEntityRef(reader.Name);

                break;

            case System.Xml.XmlNodeType.XmlDeclaration:

            case System.Xml.XmlNodeType.ProcessingInstruction:

                writer.WriteProcessingInstruction(reader.Name, reader.Value);

                break;

            case System.Xml.XmlNodeType.DocumentType:

                writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);

                break;

            case System.Xml.XmlNodeType.Comment:

                writer.WriteComment(reader.Value);

                break;

            case System.Xml.XmlNodeType.EndElement:

                writer.WriteFullEndElement();

                break;
            }

            if (reader.Read())
            {
                XmlReaderClone(reader, writer);
            }
        }