2004-09-08 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 8 Sep 2004 05:49:24 +0000 (05:49 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 8 Sep 2004 05:49:24 +0000 (05:49 -0000)
* XmlReader.cs : evidence is always provided.
* XmlWriter.cs, XmlTextWriter.cs :
  added support for ConformanceLevel and OmitXmlDeclaration.

svn path=/trunk/mcs/; revision=33558

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlReader.cs
mcs/class/System.XML/System.Xml/XmlTextWriter.cs
mcs/class/System.XML/System.Xml/XmlWriter.cs

index 530a0dcf6b4b5ac99f47440b759616fe8080a4f6..a03f94bf03cfeccfe4a6fa8afe3f8eb3dab545f3 100644 (file)
@@ -1,3 +1,9 @@
+2004-09-08  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlReader.cs : evidence is always provided.
+       * XmlWriter.cs, XmlTextWriter.cs :
+         added support for ConformanceLevel and OmitXmlDeclaration.
+
 2004-09-08  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlTextReader.cs : Console.WriteLine() injected :(
index 7420cda8a12593665a62a62d3edc055e8d00920b..a9f3546d5d90b80bf72a7882d52a9108f9b15f63 100644 (file)
@@ -57,6 +57,7 @@ namespace System.Xml
 
                protected XmlReader ()
                {
+                       evidence = new Evidence ();
                }
 
                #endregion
index ff74f08effb96dbe08b9ec4494cb3d48dd0ad9bd..49d2ea291045412cc648c10a13a75a807a329551 100644 (file)
@@ -37,7 +37,7 @@ using System.Text;
 
 namespace System.Xml
 {
-       [MonoTODO ("CheckCharacters; Conformance; NormalizeNewLines; OmitXmlDeclaration")]
+       [MonoTODO ("CheckCharacters; NormalizeNewLines")]
        public class XmlTextWriter : XmlWriter
        {
                #region Fields
@@ -84,6 +84,10 @@ namespace System.Xml
                bool closeOutput;
                bool newLineOnAttributes;
                string newLineChars;
+               bool outputXmlDeclaration;
+#if NET_2_0
+               ConformanceLevel conformanceLevel;
+#endif
 
                #endregion
 
@@ -174,6 +178,21 @@ openElements [openElementCount - 1]).IndentingOverriden;
                        set { closeOutput = value; }
                }
 
+               // As for ConformanceLevel, MS.NET is inconsistent with
+               // MSDN documentation. For example, even if ConformanceLevel
+               // is set as .Auto, multiple WriteStartDocument() calls
+               // result in an error.
+               // ms-help://MS.NETFramework.v20.en/wd_xml/html/7db8802b-53d8-4735-a637-4d2d2158d643.htm
+               [MonoTODO]
+               internal ConformanceLevel ConformanceLevel {
+                       get { return conformanceLevel; }
+                       set {
+                               conformanceLevel = value;
+                               if (value == ConformanceLevel.Fragment)
+                                       documentStarted = true;
+                       }
+               }
+
                internal string IndentChars {
 //                     get { return indentChars; }
                        set { indentChars = value == null ? String.Empty : value; }
@@ -189,6 +208,10 @@ openElements [openElementCount - 1]).IndentingOverriden;
                        set { newLineOnAttributes = value; }
                }
 
+               internal bool OmitXmlDeclaration {
+//                     get { return !outputXmlDeclaration; }
+                       set { outputXmlDeclaration = !value; }
+               }
 #endif
 
                public bool Namespaces {
@@ -248,6 +271,16 @@ openElements [openElementCount - 1]).IndentingOverriden;
                #endregion
 
                #region Methods
+#if NET_2_0
+               private void CheckStartDocument ()
+               {
+                       if (outputXmlDeclaration &&
+                               conformanceLevel == ConformanceLevel.Document &&
+                               ws == WriteState.Start)
+                               WriteStartDocument ();
+               }
+#endif
+
                private void AddMissingElementXmlns ()
                {
                        // output namespace declaration if not exist.
@@ -303,6 +336,14 @@ openElements [openElementCount - 1]).IndentingOverriden;
 
                private void CheckState ()
                {
+#if NET_2_0
+                       CheckStartDocument ();
+#endif
+                       CheckOutputState ();
+               }
+
+               private void CheckOutputState ()
+               {
                        if (!openWriter) {
                                throw new InvalidOperationException ("The Writer is closed.");
                        }
@@ -800,7 +841,8 @@ openElements [openElementCount - 1]).IndentingOverriden;
                        if (hasRoot)
                                throw new XmlException ("WriteStartDocument called twice.");
 
-                       CheckState ();
+//                     CheckState ();
+                       CheckOutputState ();
 
                        string encodingFormatting = "";
 
@@ -829,8 +871,8 @@ openElements [openElementCount - 1]).IndentingOverriden;
 
                private void WriteStartElementInternal (string prefix, string localName, string ns)
                {
-                       hasRoot = true;
                        CheckState ();
+                       hasRoot = true;
                        CloseStartElement ();
                        newAttributeNamespaces.Clear ();
                        userWrittenNamespaces.Clear ();
index e94cb9e41a2ba450b1cd904fb4fa8c71866a9de3..2a6b2ee8562037c35cbd9e3c387285047d51c300 100644 (file)
@@ -163,6 +163,10 @@ namespace System.Xml
                        xtw.CloseOutput = settings.CloseOutput;
                        // NewLineOnAttributes
                        xtw.NewLineOnAttributes = settings.NewLineOnAttributes;
+                       // ConformanceLevel
+                       xtw.ConformanceLevel = settings.ConformanceLevel;
+                       // OmitXmlDeclaration
+                       xtw.OmitXmlDeclaration = settings.OmitXmlDeclaration;
                        return Create (xtw, settings);
                }