浏览代码

2007-08-13 Atsushi Enomoto <[email protected]>

	* XmlTextWriter2.cs : fix extraneous indentation which is put after
	  omitted xmldecl.

	* XmlWriterSettingsTests.cs : added test for extraneous newline on
	  OmitXmlDeclaration mode.


svn path=/trunk/mcs/; revision=83958
Atsushi Eno 18 年之前
父节点
当前提交
08087f828c

+ 5 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,8 @@
+2007-08-13  Atsushi Enomoto  <[email protected]>
+
+	* XmlTextWriter2.cs : fix extraneous indentation which is put after
+	  omitted xmldecl.
+
 2007-08-09  Jb Evain  <[email protected]>
 
 	* XmlTextReader.cs: Avoid using 2.0 only feature in 2.1.

+ 2 - 2
mcs/class/System.XML/System.Xml/XmlTextWriter2.cs

@@ -466,8 +466,6 @@ namespace Mono.Xml
 			if (state != WriteState.Start)
 				throw StateError ("XmlDeclaration");
 
-			state = WriteState.Prolog;
-
 			switch (xmldecl_state) {
 			case XmlDeclState.Ignore:
 				return;
@@ -475,6 +473,8 @@ namespace Mono.Xml
 				throw InvalidOperation ("WriteStartDocument cannot be called when ConformanceLevel is Fragment.");
 			}
 
+			state = WriteState.Prolog;
+
 			writer.Write ("<?xml version=");
 			writer.Write (quote_char);
 			writer.Write ("1.0");

+ 5 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -1,3 +1,8 @@
+2007-08-13  Atsushi Enomoto  <[email protected]>
+
+	* XmlWriterSettingsTests.cs : added test for extraneous newline on
+	  OmitXmlDeclaration mode.
+
 2007-08-02  Atsushi Enomoto  <[email protected]>
 
 	* XsdValidatingReaderTests.cs : test for bug #82010.

+ 20 - 0
mcs/class/System.XML/Test/System.Xml/XmlWriterSettingsTests.cs

@@ -264,6 +264,26 @@ namespace MonoTests.System.Xml
 			w.Close ();
 			AssertEquals ("#2", expected, sw.ToString ().Replace ("\r\n", "\n"));
 		}
+
+		[Test]
+		public void OmitXmlDeclarationAndNewLine ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root/>");
+			XmlWriterSettings settings = new XmlWriterSettings ();
+			settings.OmitXmlDeclaration = true;
+			settings.NewLineChars = "\r\n";
+			settings.NewLineHandling = NewLineHandling.Replace;
+			settings.Encoding = Encoding.UTF8;
+			settings.Indent = true;
+
+			StringWriter sw = new StringWriter ();
+			using (XmlWriter xw = XmlWriter.Create (sw, settings)) {
+				doc.Save (xw);
+			}
+			// no heading newline.
+			AssertEquals ("<root />", sw.ToString ());
+		}
 	}
 }
 #endif