Clone() public method

public Clone ( ) : XmlWriterSettings
return XmlWriterSettings
コード例 #1
0
        private XmlWriter CreateMemWriter(XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();
            wSettings.CloseOutput = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters = false;
            XmlWriter w = null;

            switch (WriterType)
            {
                case WriterType.UTF8Writer:
                    wSettings.Encoding = Encoding.UTF8;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.UnicodeWriter:
                    wSettings.Encoding = Encoding.Unicode;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.WrappedWriter:
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    XmlWriter ww = WriterHelper.Create(_strWriter, wSettings);
                    w = WriterHelper.Create(ww, wSettings);
                    break;
                case WriterType.CharCheckingWriter:
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    XmlWriter cw = WriterHelper.Create(_strWriter, wSettings);
                    XmlWriterSettings cws = settings.Clone();
                    cws.CheckCharacters = true;
                    w = WriterHelper.Create(cw, cws);
                    break;
                case WriterType.UTF8WriterIndent:
                    wSettings.Encoding = Encoding.UTF8;
                    wSettings.Indent = true;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.UnicodeWriterIndent:
                    wSettings.Encoding = Encoding.Unicode;
                    wSettings.Indent = true;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                default:
                    throw new Exception("Unknown writer type");
            }
            return w;
        }
コード例 #2
0
        internal XmlWriter CreateWriter(string outputFileName)
        {
            if (outputFileName == null)
            {
                throw new ArgumentNullException(nameof(outputFileName));
            }

            // need to clone the settigns so that we can set CloseOutput to true to make sure the stream gets closed in the end
            XmlWriterSettings newSettings = this;

            if (!newSettings.CloseOutput)
            {
                newSettings             = newSettings.Clone();
                newSettings.CloseOutput = true;
            }

            FileStream fs = null;

            try
            {
                // open file stream
                fs = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000, _useAsync);

                // create writer
                return(newSettings.CreateWriter(fs));
            }
            catch
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
                throw;
            }
        }
コード例 #3
0
        internal XmlWriter CreateWriter(string outputFileName)
        {
            XmlWriter writer;

            if (outputFileName == null)
            {
                throw new ArgumentNullException("outputFileName");
            }
            XmlWriterSettings settings = this;

            if (!settings.CloseOutput)
            {
                settings             = settings.Clone();
                settings.CloseOutput = true;
            }
            FileStream output = null;

            try
            {
                output = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
                writer = settings.CreateWriter(output);
            }
            catch
            {
                if (output != null)
                {
                    output.Close();
                }
                throw;
            }
            return(writer);
        }
コード例 #4
0
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        private XmlAutoDetectWriter(XmlWriterSettings writerSettings) {
            Debug.Assert(writerSettings.OutputMethod == XmlOutputMethod.AutoDetect);

            this.writerSettings = (XmlWriterSettings)writerSettings.Clone();
            this.writerSettings.ReadOnly = true;

            // Start caching all events
            this.eventCache = new XmlEventCache(string.Empty, true);
        }
コード例 #5
0
ファイル: XmlWriter.cs プロジェクト: weeble/mono
        public static XmlWriter Create(XmlWriter output, XmlWriterSettings settings)
        {
            if (settings == null)
            {
                settings = new XmlWriterSettings();
            }
            else
            {
                settings = settings.Clone();
            }

            var src = output.Settings;

            if (src == null)
            {
                settings.ConformanceLevel = ConformanceLevel.Document;                 // Huh? Why??
                output = new DefaultXmlWriter(output);
#if NET_4_5
                settings.SetReadOnly();
#endif
                output.settings = settings;
            }
            else
            {
                ConformanceLevel dst = src.ConformanceLevel;
                switch (src.ConformanceLevel)
                {
                case ConformanceLevel.Auto:
                    dst = settings.ConformanceLevel;
                    break;

                case ConformanceLevel.Document:
                case ConformanceLevel.Fragment:
                    if (settings.ConformanceLevel != ConformanceLevel.Auto)
                    {
                        dst = settings.ConformanceLevel;
                    }
                    break;
                }

                settings.MergeFrom(src);

#if NET_4_5
                settings.SetReadOnly();
#endif

                // It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
                if (src.ConformanceLevel != dst)
                {
                    output          = new DefaultXmlWriter(output, false);
                    output.settings = settings;
                }
            }

            return(output);
        }
コード例 #6
0
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        private XmlAutoDetectWriter(XmlWriterSettings writerSettings)
        {
            Debug.Assert(writerSettings.OutputMethod == XmlOutputMethod.AutoDetect);

            _writerSettings          = (XmlWriterSettings)writerSettings.Clone();
            _writerSettings.ReadOnly = true;

            // Start caching all events
            _eventCache = new XmlEventCache(string.Empty, true);
        }
コード例 #7
0
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        private XmlAutoDetectWriter(XmlWriterSettings writerSettings, Encoding encoding)
        {
            Debug.Assert(writerSettings.OutputMethod == XmlOutputMethod.AutoDetect);

            this.writerSettings          = writerSettings.Clone();
            this.writerSettings.Encoding = encoding;
            this.writerSettings.ReadOnly = true;

            // Start caching all events
            this.eventCache = new XmlEventCache(string.Empty, true);
        }
コード例 #8
0
        public static XmlWriter Create(XmlWriter writer, XmlWriterSettings settings)
        {
            if (settings == null)
            {
                settings = new XmlWriterSettings();
            }
            else
            {
                settings = settings.Clone();
            }

            var src = writer.Settings;

            if (src == null)
            {
                settings.ConformanceLevel = ConformanceLevel.Document;                 // Huh? Why??
                writer          = new DefaultXmlWriter(writer);
                writer.settings = settings;
            }
            else
            {
                ConformanceLevel dst = src.ConformanceLevel;
                switch (src.ConformanceLevel)
                {
                case ConformanceLevel.Auto:
                    dst = settings.ConformanceLevel;
                    break;

                case ConformanceLevel.Document:
                case ConformanceLevel.Fragment:
                    if (settings.ConformanceLevel != ConformanceLevel.Auto)
                    {
                        dst = settings.ConformanceLevel;
                    }
                    break;
                }

                settings.MergeFrom(src);

                // It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
                if (src.ConformanceLevel != dst)
                {
                    writer          = new DefaultXmlWriter(writer, false);
                    writer.settings = settings;
                }
            }

            return(writer);
        }
コード例 #9
0
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'Entitize'", Param = NewLineHandling.Entitize, Priority = 2)]
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'Replace'", Param = NewLineHandling.Replace, Priority = 2)]
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'None'", Param = NewLineHandling.None, Priority = 2)]
        public int EOF_Handling_19()
        {
            if (WriterType == WriterType.UTF8WriterIndent || WriterType == WriterType.UnicodeWriterIndent)
                CError.Skip("skipped");
            XmlWriterSettings wSettings = new XmlWriterSettings();
            wSettings.NewLineHandling = (NewLineHandling)CurVariation.Param;
            wSettings.CheckCharacters = false;
            XmlWriter ww = CreateMemWriter(wSettings);
            XmlWriterSettings ws = wSettings.Clone();
            ws.NewLineHandling = NewLineHandling.Replace;
            ws.CheckCharacters = true;
            XmlWriter w = WriterHelper.Create(ww, ws);

            string NewLines = "\r \n " + nl;

            w.WriteStartElement("root");
            w.WriteCData(NewLines);
            w.WriteChars(NewLines.ToCharArray(), 0, NewLines.Length);
            w.WriteEndElement();
            w.WriteProcessingInstruction("pi", NewLines);
            w.WriteWhitespace(NewLines);
            w.WriteComment(NewLines);
            w.Dispose();

            string expOut;
            if ((NewLineHandling)CurVariation.Param == NewLineHandling.Entitize)
                expOut = "<root><![CDATA[" + NewLines + "]]>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "</root>" + "<?pi " + NewLines + "?>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "<!--" + NewLines + "-->";
            else
                expOut = ExpectedOutput("<root><![CDATA[" + NewLines + "]]>" + NewLines + "</root><?pi " + NewLines + "?>" + NewLines + "<!--" + NewLines + "-->", NewLineHandling.Replace, false);

            VerifyOutput(expOut);
            return TEST_PASS;
        }
コード例 #10
0
		public void AsyncPropagation ()
		{
			var sw = new StringWriter ();
			var s = new XmlWriterSettings ();
			s.Async = true;
			var w = XmlWriter.Create (sw, s);

			var c = s.Clone ();
			Assert.IsTrue (c.Async);
			c.Reset ();
			Assert.IsFalse (c.Async);

			var w2 = XmlWriter.Create (w, c);
			Assert.IsTrue (w2.Settings.Async);
		}
コード例 #11
0
 private XmlAutoDetectWriter(XmlWriterSettings writerSettings)
 {
     this.writerSettings          = writerSettings.Clone();
     this.writerSettings.ReadOnly = true;
     this.eventCache = new XmlEventCache(string.Empty, true);
 }
 private XmlAutoDetectWriter(XmlWriterSettings writerSettings)
 {
     this.writerSettings = writerSettings.Clone();
     this.writerSettings.ReadOnly = true;
     this.eventCache = new XmlEventCache(string.Empty, true);
 }
コード例 #13
0
        public XmlWriter CreateMemWriter(Stream writerStream, XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();
            wSettings.CloseOutput = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters = false;
            XmlWriter w = null;

            switch (WriterType)
            {
                case WriterType.UTF8Writer:
                    wSettings.Encoding = Encoding.UTF8;
                    w = WriterHelper.Create(writerStream, wSettings);
                    break;
                case WriterType.UnicodeWriter:
                    wSettings.Encoding = Encoding.Unicode;
                    w = WriterHelper.Create(writerStream, wSettings);
                    break;
                case WriterType.WrappedWriter:
                    XmlWriter ww = WriterHelper.Create(writerStream, wSettings);
                    w = WriterHelper.Create(ww, wSettings);
                    break;
                case WriterType.CharCheckingWriter:
                    XmlWriter cw = WriterHelper.Create(writerStream, wSettings);
                    XmlWriterSettings cws = settings.Clone();
                    cws.CheckCharacters = true;
                    w = WriterHelper.Create(cw, cws);
                    break;
                case WriterType.CustomWriter:
                    w = new CustomWriter(writerStream, wSettings);
                    break;
                case WriterType.UTF8WriterIndent:
                    wSettings.Encoding = Encoding.UTF8;
                    wSettings.Indent = true;
                    w = WriterHelper.Create(writerStream, wSettings);
                    break;
                case WriterType.UnicodeWriterIndent:
                    wSettings.Encoding = Encoding.Unicode;
                    wSettings.Indent = true;
                    w = WriterHelper.Create(writerStream, wSettings);
                    break;
                default:
                    throw new Exception("Unknown writer type");
            }
            return w;
        }
コード例 #14
0
        //[Variation(id=2, Desc="Test for Clone()", Pri=0)]
        public int Clone_1()
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();
            wSettings.Encoding = Encoding.UTF8;
            wSettings.OmitXmlDeclaration = true;
            wSettings.NewLineHandling = NewLineHandling.Entitize;
            wSettings.NewLineChars = "\n";
            wSettings.IndentChars = "                ";
            wSettings.NewLineOnAttributes = true;
            wSettings.CloseOutput = true;
            wSettings.CheckCharacters = false;
            wSettings.ConformanceLevel = ConformanceLevel.Document;
            wSettings.WriteEndDocumentOnClose = false;

            XmlWriterSettings newSettings = wSettings.Clone();

            CError.Equals(wSettings.Encoding, newSettings.Encoding, "Encoding");
            CError.Equals(wSettings.OmitXmlDeclaration, newSettings.OmitXmlDeclaration, "OmitXmlDeclaration");
            CError.Equals(wSettings.NewLineHandling, newSettings.NewLineHandling, "NewLineHandling");
            CError.Equals(wSettings.NewLineChars, newSettings.NewLineChars, "NewLineChars");
            CError.Equals(wSettings.Indent, newSettings.Indent, "Indent");
            CError.Equals(wSettings.IndentChars, newSettings.IndentChars, "IndentChars");
            CError.Equals(wSettings.NewLineOnAttributes, newSettings.NewLineOnAttributes, "NewLineOnAttributes");
            CError.Equals(wSettings.CloseOutput, newSettings.CloseOutput, "CloseOutput");
            CError.Equals(wSettings.CheckCharacters, newSettings.CheckCharacters, "CheckCharacters");
            CError.Equals(wSettings.ConformanceLevel, newSettings.ConformanceLevel, "ConformanceLevel");
            CError.Equals(wSettings.WriteEndDocumentOnClose, newSettings.WriteEndDocumentOnClose, "WriteEndDocumentOnClose");

            return TEST_PASS;
        }
コード例 #15
0
 //[Variation(Desc = "NamespaceHandling wrap with OmitDuplicates.Default", Param = NamespaceHandling.Default)]
 //[Variation(Desc = "NamespaceHandling wrap with OmitDuplicates.OmitDuplicates", Param = NamespaceHandling.OmitDuplicates)]
 public int NS_Handling_4b()
 {
     XmlWriterSettings wSettings = new XmlWriterSettings();
     wSettings.NamespaceHandling = (NamespaceHandling)this.CurVariation.Param;
     using (XmlWriter ww = CreateMemWriter(wSettings))
     {
         XmlWriterSettings ws = wSettings.Clone();
         ws.NamespaceHandling = NamespaceHandling.OmitDuplicates;
         ws.CheckCharacters = true;
         using (XmlWriter w = WriterHelper.Create(ww, ws))
         {
             CError.Compare(w != null, "XmlWriter creation failed");
             CError.Compare(w.Settings.NamespaceHandling, (NamespaceHandling)this.CurVariation.Param, "Invalid NamespaceHandling assignment");
         }
     }
     return TEST_PASS;
 }