当前位置: 首页>>代码示例>>C#>>正文


C# XmlWriterSettings.Clone方法代码示例

本文整理汇总了C#中XmlWriterSettings.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriterSettings.Clone方法的具体用法?C# XmlWriterSettings.Clone怎么用?C# XmlWriterSettings.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlWriterSettings的用法示例。


在下文中一共展示了XmlWriterSettings.Clone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMemWriter

        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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:55,代码来源:EndOfLineHandlingTests.cs

示例2: NS_Handling_4b

 //[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;
 }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:19,代码来源:NamespaceHandlingTests.cs

示例3: CreateMemWriter

        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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:46,代码来源:XmlFactoryWriterTests.cs

示例4: Clone_1

        //[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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:31,代码来源:XmlFactoryWriterTests.cs

示例5: EOF_Handling_19

        //[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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:36,代码来源:EndOfLineHandlingTests.cs


注:本文中的XmlWriterSettings.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。