Exemplo n.º 1
0
        private static string HandleNormalization(string content, NewLineHandling newLineHandling, bool trimEachLine)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(content);
            }

            if (trimEachLine)
            {
                content = content.Trim();
            }

            StringBuilder newContent = new StringBuilder();
            int           lastIndex  = 0;
            int           index;
            string        newLine = GetDefaultNewLine(newLineHandling);

            while ((index = content.IndexOf('\n', lastIndex)) >= 0)
            {
                AppendContent(content, trimEachLine, newContent, lastIndex, index);
                AppendNewLine(content, trimEachLine, newContent, index, newLine);

                lastIndex = index + 1;
            }

            AppendContent(content, trimEachLine, newContent, lastIndex, content.Length);

            return(newContent.ToString());
        }
Exemplo n.º 2
0
//
// Private methods
//
        void Initialize()
        {
            encoding                = Encoding.UTF8;
            omitXmlDecl             = false;
            newLineHandling         = NewLineHandling.Replace;
            newLineChars            = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            indent                  = TriState.Unknown;
            indentChars             = "  ";
            newLineOnAttributes     = false;
            closeOutput             = false;
            namespaceHandling       = NamespaceHandling.Default;
            conformanceLevel        = ConformanceLevel.Document;
            checkCharacters         = true;
            writeEndDocumentOnClose = true;

#if !SILVERLIGHT
            outputMethod = XmlOutputMethod.Xml;
            cdataSections.Clear();
            mergeCDataSections       = false;
            mediaType                = null;
            docTypeSystem            = null;
            docTypePublic            = null;
            standalone               = XmlStandalone.Omit;
            doNotEscapeUriAttributes = false;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif
            isReadOnly = false;
        }
        public void EOF_Handling_08(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings           = new XmlWriterSettings();
            string            NewLineCombinations = "\r \n \r\n \n\r \r\r \n\n \r\n\r \n\r\n";
            string            NewLineEntities     = "
 
 
 

 

 

 

 

";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteStartAttribute("foo");

            for (int i = 0; i < NewLineCombinations.Length; i++)
            {
                if (NewLineCombinations[i] == ' ')
                {
                    w.WriteString(" ");
                }
                else
                {
                    w.WriteCharEntity(NewLineCombinations[i]);
                }
            }

            w.WriteEndAttribute();
            w.WriteEndElement();
            w.Dispose();
            VerifyOutput("<root foo=\"" + ExpectedOutput(NewLineEntities, nlHandling, true) + "\" />");

            return;
        }
        //
        // Private methods
        //
        private void Initialize()
        {
            _encoding                = Encoding.UTF8;
            _omitXmlDecl             = false;
            _newLineHandling         = NewLineHandling.Replace;
            _newLineChars            = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            _indent                  = TriState.Unknown;
            _indentChars             = "  ";
            _newLineOnAttributes     = false;
            _closeOutput             = false;
            _namespaceHandling       = NamespaceHandling.Default;
            _conformanceLevel        = ConformanceLevel.Document;
            _checkCharacters         = true;
            _writeEndDocumentOnClose = true;

            _outputMethod = XmlOutputMethod.Xml;
            _cdataSections.Clear();
            _mergeCDataSections       = false;
            _mediaType                = null;
            _docTypeSystem            = null;
            _docTypePublic            = null;
            _standalone               = XmlStandalone.Omit;
            _doNotEscapeUriAttributes = false;

            _useAsync   = false;
            _isReadOnly = false;
        }
        public void EOF_Handling_17(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();
            string            NewLines  = "\r \n \r\n";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            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();

            // Inside Comments and CDATA blocks NewLines are never entitized (needs spec BUG)
            string expOut;

            if (nlHandling == 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 + "-->", nlHandling, false);
            }

            VerifyOutput(expOut);
        }
        public void EOF_Handling_18(XmlWriterUtils utils, NewLineHandling nlHandling, string newLineChars)
        {
            XmlWriterSettings wSettings       = new XmlWriterSettings();
            string            PrototypeOutput = "<root><![CDATA[foo&NewLinefoo&NewLinefoo&NewLinefoo\tfoo]]></root>&NewLine<?pi foo&NewLinefoo&NewLinefoo&NewLinefoo\tfoo?>&NewLine<!--foo&NewLinefoo&NewLinefoo&NewLinefoo\tfoo-->";

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;
            wSettings.NewLineChars    = newLineChars;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteCData("foo\r\nfoo\nfoo\rfoo\tfoo");
            w.WriteEndElement();
            w.WriteProcessingInstruction("pi", "foo\r\nfoo\nfoo\rfoo\tfoo");
            w.WriteComment("foo\r\nfoo\nfoo\rfoo\tfoo");
            w.Dispose();

            if (nlHandling == NewLineHandling.Replace)
            {
                VerifyOutput(PrototypeOutput.Replace("&NewLine", newLineChars));
            }
            else
            {
                VerifyOutput("<root><![CDATA[foo\r\nfoo\nfoo\rfoo\tfoo]]></root>&NewLine<?pi foo\r\nfoo\nfoo\rfoo\tfoo?>&NewLine<!--foo\r\nfoo\nfoo\rfoo\tfoo-->".Replace("&NewLine", newLineChars));
            }

            return;
        }
Exemplo n.º 7
0
 private string ExpectedOutput(string input, NewLineHandling h, bool attr)
 {
     string output = input;
     switch (h)
     {
         case NewLineHandling.Entitize:
             output = output.Replace("\r", "&#xD;");
             if (attr)
             {
                 output = output.Replace("\n", "&#xA;");
                 output = output.Replace("\t", "&#x9;");
             }
             break;
         case NewLineHandling.Replace:
             if (!attr)
             {
                 output = output.Replace("\r\n", "\n");
                 output = output.Replace("\r", "\n");
                 output = output.Replace("\n", "\r\n");
             }
             else
             {
                 output = output.Replace("\r", "&#xD;");
                 output = output.Replace("\n", "&#xA;");
                 output = output.Replace("\t", "&#x9;");
             }
             break;
         default:
             break;
     }
     return output;
 }
        private string ExpectedOutput(string input, NewLineHandling h, bool attr)
        {
            string output = input;

            switch (h)
            {
            case NewLineHandling.Entitize:
                output = output.Replace("\r", "&#xD;");
                if (attr)
                {
                    output = output.Replace("\n", "&#xA;");
                    output = output.Replace("\t", "&#x9;");
                }
                break;

            case NewLineHandling.Replace:
                if (!attr)
                {
                    output = output.Replace("\r\n", "\n");
                    output = output.Replace("\r", "\n");
                    output = output.Replace("\n", Environment.NewLine);
                }
                else
                {
                    output = output.Replace("\r", "&#xD;");
                    output = output.Replace("\n", "&#xA;");
                    output = output.Replace("\t", "&#x9;");
                }
                break;

            default:
                break;
            }
            return(output);
        }
Exemplo n.º 9
0
 public MarkdownWriterSettings(
     MarkdownFormat format           = null,
     string newLineChars             = null,
     NewLineHandling newLineHandling = NewLineHandling.Replace,
     bool closeOutput = false)
 {
     Format          = format ?? MarkdownFormat.Default;
     NewLineChars    = newLineChars ?? Environment.NewLine;
     NewLineHandling = newLineHandling;
     CloseOutput     = closeOutput;
 }
        public void EOF_Handling_02(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            XmlWriter w = CreateMemWriter(utils, wSettings);

            CError.Compare(w != null, "XmlWriter creation failed");
            CError.Compare(w.Settings.NewLineHandling, nlHandling, "Invalid NewLineHandling assignment");
            w.Dispose();

            return;
        }
Exemplo n.º 11
0
 /// <summary>Resets the members of the settings class to their default values.</summary>
 public void Reset()
 {
     this.checkCharacters     = true;
     this.closeOutput         = false;
     this.conformance         = ConformanceLevel.Document;
     this.encoding            = Encoding.UTF8;
     this.indent              = false;
     this.indentChars         = "  ";
     this.newLineChars        = Environment.NewLine;
     this.newLineOnAttributes = false;
     this.newLineHandling     = NewLineHandling.None;
     this.omitXmlDeclaration  = false;
     this.outputMethod        = XmlOutputMethod.AutoDetect;
 }
Exemplo n.º 12
0
 public void Reset()
 {
     checkCharacters     = true;
     closeOutput         = false;     // ? not documented
     conformance         = ConformanceLevel.Document;
     encoding            = Encoding.UTF8;
     indent              = false;
     indentChars         = "  ";
     newLineChars        = "\r\n";
     newLineOnAttributes = false;
     newLineHandling     = NewLineHandling.Replace;
     omitXmlDeclaration  = false;
     outputMethod        = XmlOutputMethod.AutoDetect;
     isAsync             = false;
 }
		public void Reset()
		{
			checkCharacters = true;
			closeOutput = false;
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			newLineChars = Environment.NewLine;
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.Replace;
			normalizeNewLines = true;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
		}
		private XmlWriterSettings(XmlWriterSettings org)
		{
			checkCharacters = org.checkCharacters;
			closeOutput = org.closeOutput;
			conformance = org.conformance;
			encoding = org.encoding;
			indent = org.indent;
			indentChars = org.indentChars;
			newLineChars = org.newLineChars;
			newLineOnAttributes = org.newLineOnAttributes;
			newLineHandling = org.newLineHandling;
			normalizeNewLines = org.normalizeNewLines;
			outputMethod = org.outputMethod;
			omitXmlDeclaration = org.omitXmlDeclaration;
		}
Exemplo n.º 15
0
 public void Reset()
 {
     checkCharacters     = true;
     closeOutput         = false;
     conformance         = ConformanceLevel.Document;
     encoding            = Encoding.UTF8;
     indent              = false;
     indentChars         = "  ";
     newLineChars        = Environment.NewLine;
     newLineOnAttributes = false;
     newLineHandling     = NewLineHandling.Replace;
     normalizeNewLines   = true;
     omitXmlDeclaration  = false;
     outputMethod        = XmlOutputMethod.AutoDetect;
 }
Exemplo n.º 16
0
 private XmlWriterSettings(XmlWriterSettings org)
 {
     checkCharacters     = org.checkCharacters;
     closeOutput         = org.closeOutput;
     conformance         = org.conformance;
     encoding            = org.encoding;
     indent              = org.indent;
     indentChars         = org.indentChars;
     newLineChars        = org.newLineChars;
     newLineOnAttributes = org.newLineOnAttributes;
     newLineHandling     = org.newLineHandling;
     normalizeNewLines   = org.normalizeNewLines;
     outputMethod        = org.outputMethod;
     omitXmlDeclaration  = org.omitXmlDeclaration;
 }
Exemplo n.º 17
0
 public void Reset()
 {
     checkCharacters = true;
     closeOutput     = false; // ? not documented
     conformance     = ConformanceLevel.Document;
     encoding        = Encoding.UTF8;
     indent          = false;
     indentChars     = "  ";
     // LAMESPEC: MS.NET says it is "\r\n", but it is silly decision.
     newLineChars        = Environment.NewLine;
     newLineOnAttributes = false;
     newLineHandling     = NewLineHandling.None;
     omitXmlDeclaration  = false;
     outputMethod        = XmlOutputMethod.AutoDetect;
 }
		public void Reset ()
		{
			checkCharacters = true;
			closeOutput = false; // ? not documented
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			// LAMESPEC: MS.NET says it is "\r\n", but it is silly decision.
			newLineChars = Environment.NewLine;
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.None;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
		}
        public void EOF_Handling_03(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings           = new XmlWriterSettings();
            string            NewLineCombinations = "\r \n \r\n \n\r \r\r \n\n \r\n\r \n\r\n";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteElementString("root", NewLineCombinations);
            w.Dispose();
            VerifyOutput("<root>" + ExpectedOutput(NewLineCombinations, nlHandling, false) + "</root>");

            return;
        }
        public void EOF_Handling_07(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings           = new XmlWriterSettings();
            string            NewLineCombinations = "\r \n \r\n \n\r \r\r \n\n \r\n\r \n\r\n";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteAttributeString("foo", NewLineCombinations);
            w.WriteEndElement();
            w.Dispose();
            VerifyOutput("<root foo=\"" + ExpectedOutput(NewLineCombinations, nlHandling, true) + "\" />");

            return;
        }
        public void EOF_Handling_15(XmlWriterUtils utils, NewLineHandling nlHandling, string newLineChars)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;
            wSettings.NewLineChars    = newLineChars;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteAttributeString("foo", "foo\r\nfoo\nfoo\rfoo\tfoo");
            w.WriteEndElement();
            w.Dispose();

            VerifyOutput("<root foo=\"" + ExpectedOutput("foo\r\nfoo\nfoo\rfoo\tfoo", nlHandling, true) + "\" />");
        }
Exemplo n.º 22
0
        //
        // Constructors
        //
        // Construct and initialize an instance of this class.
        protected XmlUtf8RawTextWriter(XmlWriterSettings settings)
        {
            _useAsync = settings.Async;

            // copy settings
            newLineHandling = settings.NewLineHandling;
            omitXmlDeclaration = settings.OmitXmlDeclaration;
            newLineChars = settings.NewLineChars;
            checkCharacters = settings.CheckCharacters;
            closeOutput = settings.CloseOutput;


            if (checkCharacters && newLineHandling == NewLineHandling.Replace)
            {
                ValidateContentChars(newLineChars, "NewLineChars", false);
            }
        }
        public void EOF_Handling_09(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();
            string            NewLines  = "\r&#xA; &#xD;\n &#xD;\r &#xA;\n \n&#xD; &#xA;\r";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteStartAttribute("foo");

            // '\r&#xA; '
            w.WriteString("\r");
            w.WriteCharEntity('\n');
            w.WriteString(" ");

            // '&#xD;\n '
            w.WriteCharEntity('\r');
            w.WriteString("\n ");

            // '&#xD;\r '
            w.WriteCharEntity('\r');
            w.WriteString("\r ");

            // '&#xA;\n '
            w.WriteCharEntity('\n');
            w.WriteString("\n ");

            // '\n&#xD; '
            w.WriteString("\n");
            w.WriteCharEntity('\r');
            w.WriteString(" ");

            // '&#xA;\r'
            w.WriteCharEntity('\n');
            w.WriteString("\r");

            w.WriteEndAttribute();
            w.WriteEndElement();
            w.Dispose();
            VerifyOutput("<root foo=\"" + ExpectedOutput(NewLines, nlHandling, true) + "\" />");

            return;
        }
Exemplo n.º 24
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _encoding                = Encoding.UTF8;
            _omitXmlDecl             = false;
            _newLineHandling         = NewLineHandling.Replace;
            _newLineChars            = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            _indent                  = TriState.Unknown;
            _indentChars             = "  ";
            _newLineOnAttributes     = false;
            _closeOutput             = false;
            _namespaceHandling       = NamespaceHandling.Default;
            _conformanceLevel        = ConformanceLevel.Document;
            _checkCharacters         = true;
            _writeEndDocumentOnClose = true;


            _useAsync   = false;
            _isReadOnly = false;
        }
 protected XmlEncodedRawTextWriter(XmlWriterSettings settings)
 {
     this.xmlCharType = XmlCharType.Instance;
     this.bufPos = 1;
     this.textPos = 1;
     this.bufLen = 0x1800;
     this.newLineHandling = settings.NewLineHandling;
     this.omitXmlDeclaration = settings.OmitXmlDeclaration;
     this.newLineChars = settings.NewLineChars;
     this.checkCharacters = settings.CheckCharacters;
     this.closeOutput = settings.CloseOutput;
     this.standalone = settings.Standalone;
     this.outputMethod = settings.OutputMethod;
     this.mergeCDataSections = settings.MergeCDataSections;
     if (this.checkCharacters && (this.newLineHandling == NewLineHandling.Replace))
     {
         this.ValidateContentChars(this.newLineChars, "NewLineChars", false);
     }
 }
Exemplo n.º 26
0
 protected XmlUtf8RawTextWriter(XmlWriterSettings settings)
 {
     this.xmlCharType        = XmlCharType.Instance;
     this.bufPos             = 1;
     this.textPos            = 1;
     this.bufLen             = 0x1800;
     this.newLineHandling    = settings.NewLineHandling;
     this.omitXmlDeclaration = settings.OmitXmlDeclaration;
     this.newLineChars       = settings.NewLineChars;
     this.checkCharacters    = settings.CheckCharacters;
     this.closeOutput        = settings.CloseOutput;
     this.standalone         = settings.Standalone;
     this.outputMethod       = settings.OutputMethod;
     this.mergeCDataSections = settings.MergeCDataSections;
     if (this.checkCharacters && (this.newLineHandling == NewLineHandling.Replace))
     {
         this.ValidateContentChars(this.newLineChars, "NewLineChars", false);
     }
 }
Exemplo n.º 27
0
		///<summary>
		/// Return an XmlWriterSettings suitable for use in Chorus applications.
		///</summary>
		/// <remarks>
		/// This formats with new line on attributes, indents with tab, and encoded in UTF8 with no BOM.
		/// </remarks>
		/// <param name="conformanceLevel">Document|Fragment</param>
		/// <param name = "newLineHandling">Indicates how to normalize line breaks in the output.</param>
		///<returns>XmlWriterSettings</returns>
		public static XmlWriterSettings CreateXmlWriterSettings(ConformanceLevel conformanceLevel,
			NewLineHandling newLineHandling = NewLineHandling.Replace)
		{
			var settings = new XmlWriterSettings
			{
				NewLineOnAttributes = true,			// New line for each attribute, saves space on a typical Chorus changeset.
				Indent = true,						// Indent entities
				IndentChars = "\t",					// Tabs for the indent
				CheckCharacters = false,
				Encoding = new UTF8Encoding(false),	// UTF8 without a BOM.
				CloseOutput = true,					// Close the underlying stream on Close.  This is not the default.
				ConformanceLevel = conformanceLevel,
				NewLineChars = "\r\n",				// Use /r/n for our end of lines
				// NOTE: .NET and Mono (3.4) behave differently with NewLineHandling.Replace when calling XmlWriter.WriteRaw():
				// .NET will still replace line endings whereas Mono will write the data as-is.
				NewLineHandling = newLineHandling,	// Normalize line endings
				OmitXmlDeclaration = false			// The default, an xml declaration is written
			};
			return settings;
		}
        public void EOF_Handling_16(XmlWriterUtils utils, NewLineHandling nlHandling, string newLineChars)
        {
            XmlWriterSettings wSettings       = new XmlWriterSettings();
            string            PrototypeOutput = "<root&NewLine  foo=\"fooval\"&NewLine  bar=\"barval\" />";

            wSettings.NewLineHandling     = nlHandling;
            wSettings.Indent              = true;
            wSettings.NewLineChars        = newLineChars;
            wSettings.NewLineOnAttributes = true;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteAttributeString("foo", "fooval");
            w.WriteAttributeString("bar", "barval");
            w.WriteEndElement();
            w.Dispose();

            VerifyOutput(PrototypeOutput.Replace("&NewLine", newLineChars));
        }
        public void EOF_Handling_22(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;
            wSettings.NewLineChars    = "\uDE40\uDA72";
            wSettings.IndentChars     = "\uDE40\uDA72";

            XmlWriter w = CreateMemWriter(utils, wSettings);

            try
            {
                w.WriteStartElement("root");
                w.WriteStartElement("foo");
                w.Dispose();
            }
            catch (ArgumentException e) { CError.WriteLine(e.Message); return; }
            Assert.True(false);
        }
Exemplo n.º 30
0
        private static string GetDefaultNewLine(NewLineHandling newLineHandling)
        {
            string newLine = null;

            switch (newLineHandling)
            {
            case NewLineHandling.Auto:
                newLine = Environment.NewLine;
                break;

            case NewLineHandling.Windows:
                newLine = "\r\n";
                break;

            case NewLineHandling.Unix:
                newLine = "\n";
                break;
            }

            return(newLine);
        }
        public void EOF_Handling_06(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();
            string            Tabs      = "foo\tbar&#x9;foo\n\tbar\t\n\t";

            wSettings.NewLineHandling = nlHandling;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");

            w.WriteString("foo\tbar");
            w.WriteCharEntity('\t');
            w.WriteString("foo\n\tbar\t\n\t");

            w.WriteEndElement();
            w.Dispose();
            VerifyOutput("<root>" + ExpectedOutput(Tabs, nlHandling, false) + "</root>");

            return;
        }
        public void EOF_Handling_11(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            CError.Compare(w.Settings.NewLineChars, Environment.NewLine, "Incorrect default value for XmlWriter.Settings.NewLineChars");
            CError.Compare(w.Settings.IndentChars, "  ", "Incorrect default value for XmlWriter.Settings.IndentChars");

            w.WriteStartElement("root");
            w.WriteStartElement("foo");
            w.WriteElementString("bar", "");
            w.WriteEndElement();
            w.WriteEndElement();
            w.Dispose();

            VerifyOutput(string.Format("<root>{0}  <foo>{0}    <bar />{0}  </foo>{0}</root>", Environment.NewLine));
        }
        public void EOF_Handling_21(XmlWriterUtils utils, NewLineHandling nlHandling, string newLineChars, string indentChars)
        {
            XmlWriterSettings wSettings       = new XmlWriterSettings();
            string            PrototypeOutput = "<root>&NewLine&Indent<foo>&NewLine&Indent&Indent<bar />&NewLine&Indent</foo>&NewLine</root>";

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;
            wSettings.NewLineChars    = newLineChars;
            wSettings.IndentChars     = indentChars;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteStartElement("root");
            w.WriteStartElement("foo");
            w.WriteElementString("bar", "");
            w.WriteEndElement();
            w.WriteEndElement();
            w.Dispose();

            VerifyOutput(PrototypeOutput.Replace("&NewLine", newLineChars).Replace("&Indent", indentChars));
            return;
        }
        public void EOF_Handling_19(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            wSettings.CheckCharacters = false;
            XmlWriter         ww = CreateMemWriter(utils, wSettings);
            XmlWriterSettings ws = wSettings.Clone();

            ws.NewLineHandling = NewLineHandling.Replace;
            ws.CheckCharacters = true;
            XmlWriter w = WriterHelper.Create(ww, ws, overrideAsync: true, async: utils.Async);

            string NewLines = "\r \n " + Environment.NewLine;

            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 (nlHandling == 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;
        }
        public void EOF_Handling_14(XmlWriterUtils utils, NewLineHandling nlHandling, string newLineChars)
        {
            XmlWriterSettings wSettings       = new XmlWriterSettings();
            string            PrototypeOutput = "<root>foo&NewLinefoo&NewLinefoo&NewLinefoo\tfoo</root>";

            wSettings.NewLineHandling = nlHandling;
            wSettings.Indent          = true;
            wSettings.NewLineChars    = newLineChars;

            XmlWriter w = CreateMemWriter(utils, wSettings);

            w.WriteElementString("root", "foo\r\nfoo\nfoo\rfoo\tfoo");
            w.Dispose();

            if (nlHandling == NewLineHandling.Replace)
            {
                VerifyOutput(PrototypeOutput.Replace("&NewLine", newLineChars));
            }
            else
            {
                VerifyOutput("<root>" + ExpectedOutput("foo\r\nfoo\nfoo\rfoo\tfoo", nlHandling, false) + "</root>");
            }
        }
Exemplo n.º 36
0
//
// Public methods
//
        public void Reset()
        {
            encoding            = Encoding.UTF8;
            omitXmlDecl         = false;
            newLineHandling     = NewLineHandling.Replace;
            newLineChars        = "\r\n";
            indent              = TriState.Unknown;
            indentChars         = "  ";
            newLineOnAttributes = false;
            closeOutput         = false;

            conformanceLevel = ConformanceLevel.Document;
            checkCharacters  = true;

            outputMethod       = XmlOutputMethod.Xml;
            cdataSections      = null;
            mergeCDataSections = false;
            mediaType          = null;
            docTypeSystem      = null;
            docTypePublic      = null;
            standalone         = XmlStandalone.Omit;

            isReadOnly = false;
        }
//
// Private methods
//
        void Initialize() {
            encoding = Encoding.UTF8;
            omitXmlDecl = false;
            newLineHandling = NewLineHandling.Replace;
            newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            indent = TriState.Unknown;
            indentChars = "  ";
            newLineOnAttributes = false;
            closeOutput = false;
            namespaceHandling = NamespaceHandling.Default;
            conformanceLevel = ConformanceLevel.Document;
            checkCharacters = true;
            writeEndDocumentOnClose = true;

#if !SILVERLIGHT
            outputMethod = XmlOutputMethod.Xml;
            cdataSections.Clear();
            mergeCDataSections = false;
            mediaType = null;
            docTypeSystem = null;
            docTypePublic = null;
            standalone = XmlStandalone.Omit;
            doNotEscapeUriAttributes = false;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif
            isReadOnly = false;
        }
//
// Public methods
//
        public void Reset() {
            encoding = Encoding.UTF8;
            omitXmlDecl = false;
            newLineHandling = NewLineHandling.Replace;
            newLineChars = "\r\n";
            indent = TriState.Unknown;
            indentChars = "  ";
            newLineOnAttributes = false;
            closeOutput = false;

            conformanceLevel = ConformanceLevel.Document;
            checkCharacters = true;

            outputMethod = XmlOutputMethod.Xml;
            cdataSections = null;
            mergeCDataSections = false;
            mediaType = null;
            docTypeSystem = null;
            docTypePublic = null;
            standalone = XmlStandalone.Omit;

            isReadOnly = false;
        }
Exemplo n.º 39
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _encoding = Encoding.UTF8;
            _omitXmlDecl = false;
            _newLineHandling = NewLineHandling.Replace;
            _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            _indent = TriState.Unknown;
            _indentChars = "  ";
            _newLineOnAttributes = false;
            _closeOutput = false;
            _namespaceHandling = NamespaceHandling.Default;
            _conformanceLevel = ConformanceLevel.Document;
            _checkCharacters = true;
            _writeEndDocumentOnClose = true;

            _outputMethod = XmlOutputMethod.Xml;
            _cdataSections.Clear();
            _mergeCDataSections = false;
            _mediaType = null;
            _docTypeSystem = null;
            _docTypePublic = null;
            _standalone = XmlStandalone.Omit;
            _doNotEscapeUriAttributes = false;

            _useAsync = false;
            _isReadOnly = false;
        }
Exemplo n.º 40
0
		internal XmlTextWriter (
			TextWriter writer, XmlWriterSettings settings, bool closeOutput)
		{
			v2 = true;

			if (settings == null)
				settings = new XmlWriterSettings ();

			newline_handling = settings.NewLineHandling;
			Initialize (writer);

			close_output_stream = closeOutput;
			allow_doc_fragment =
				settings.ConformanceLevel != ConformanceLevel.Document;
			switch (settings.ConformanceLevel) {
			case ConformanceLevel.Auto:
				xmldecl_state = settings.OmitXmlDeclaration ? XmlDeclState.Ignore : XmlDeclState.Allow;
				break;
			case ConformanceLevel.Document:
				// LAMESPEC:
				// On MSDN, XmlWriterSettings.OmitXmlDeclaration is documented as:
				// "The XML declaration is always written if
				//  ConformanceLevel is set to Document, even 
				//  if OmitXmlDeclaration is set to true. "
				// but it is incorrect. It does consider 
				// OmitXmlDeclaration property.
				xmldecl_state = settings.OmitXmlDeclaration ? XmlDeclState.Ignore : XmlDeclState.Auto;
				break;
			case ConformanceLevel.Fragment:
				xmldecl_state = XmlDeclState.Prohibit;
				break;
			}
			if (settings.Indent)
				Formatting = Formatting.Indented;
			indent_string = settings.IndentChars == null ?
				String.Empty : settings.IndentChars;
			if (settings.NewLineChars != null)
				newline = settings.NewLineChars;
			indent_attributes = settings.NewLineOnAttributes;

			check_character_validity = settings.CheckCharacters;
			namespace_handling = settings.NamespaceHandling;
		}
Exemplo n.º 41
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _encoding = Encoding.UTF8;
            _omitXmlDecl = false;
            _newLineHandling = NewLineHandling.Replace;
            _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            _indent = TriState.Unknown;
            _indentChars = "  ";
            _newLineOnAttributes = false;
            _closeOutput = false;
            _namespaceHandling = NamespaceHandling.Default;
            _conformanceLevel = ConformanceLevel.Document;
            _checkCharacters = true;
            _writeEndDocumentOnClose = true;


            _useAsync = false;
            _isReadOnly = false;
        }
//
// Constructors
//
        // Construct and initialize an instance of this class.
        protected XmlEncodedRawTextWriter( XmlWriterSettings settings ) {

#if ASYNC
            useAsync = settings.Async;
#endif

            // copy settings
            newLineHandling = settings.NewLineHandling;
            omitXmlDeclaration = settings.OmitXmlDeclaration;
            newLineChars = settings.NewLineChars;
            checkCharacters = settings.CheckCharacters;
            closeOutput = settings.CloseOutput;

            standalone = settings.Standalone;
            outputMethod = settings.OutputMethod;
            mergeCDataSections = settings.MergeCDataSections;

            if ( checkCharacters && newLineHandling == NewLineHandling.Replace ) {
                ValidateContentChars( newLineChars, "NewLineChars", false );
            }
        }
Exemplo n.º 43
0
		public void Reset ()
		{
			checkCharacters = true;
			closeOutput = false; // ? not documented
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			newLineChars = "\r\n";
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.Replace;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
#if NET_4_5
			isAsync = false;
#endif
		}
//
// Constructors
//
        // Construct and initialize an instance of this class.
        protected XmlUtf8RawTextWriter( XmlWriterSettings settings, bool closeOutput ) {
            // copy settings
            newLineHandling = settings.NewLineHandling;
            omitXmlDeclaration = settings.OmitXmlDeclaration;
            newLineChars = settings.NewLineChars;
            standalone = settings.Standalone;
            outputMethod = settings.OutputMethod;
            checkCharacters = settings.CheckCharacters;
            mergeCDataSections = settings.MergeCDataSections;
            this.closeOutput = closeOutput;

            if ( checkCharacters && newLineHandling == NewLineHandling.Replace ) {
                ValidateContentChars( newLineChars, "NewLineChars", false );
            }
        }