2005-12-09 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 9 Dec 2005 16:37:22 +0000 (16:37 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 9 Dec 2005 16:37:22 +0000 (16:37 -0000)
* XmlInputStream.cs :
  Added Encoding property on NonBlockingStreamReader
* XmlTextReader.cs :
  set Encoding property when it proceeds to xml declaration.

* XmlTextReaderTests.cs : added test for Encoding property.

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

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlInputStream.cs
mcs/class/System.XML/System.Xml/XmlTextReader.cs
mcs/class/System.XML/Test/System.Xml/ChangeLog
mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs

index 3714cb8c936f1aeb2b9f3a156c6cb78c5ef94f38..acc3baebe43dd071c0dd9184613e524ab4271eb4 100644 (file)
@@ -1,3 +1,10 @@
+2005-12-09  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XmlInputStream.cs :
+         Added Encoding property on NonBlockingStreamReader
+       * XmlTextReader.cs :
+         set Encoding property when it proceeds to xml declaration.
+
 2005-12-09  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlReader.cs : ReadToDescendant() should work when its ReadState is
index 22936fe4af3b968fced3057cf7fe6128111f0cce..74df8f7180b0797b3c5a40aaab5c54c5f445d9de 100644 (file)
@@ -122,6 +122,10 @@ namespace System.Xml
                        pos = 0;
                }
 
+               public Encoding Encoding {
+                       get { return encoding; }
+               }
+
                public override void Close ()
                {
                        Dispose (true);
index febbd4dd7303e76741c2a166411930404870e49e..430fc76c22f6c1708a9ce2056bc57eeacbd995bd 100644 (file)
@@ -1980,6 +1980,16 @@ namespace System.Xml
                        if (message != null)
                                throw NotWFError (message);
 
+                       string encoding = GetAttribute ("encoding");
+                       if (encoding != null) {
+                               if (!XmlChar.IsValidIANAEncoding (encoding))
+                                       throw new XmlException (String.Format ("Encoding name must be a valid IANA name: {0}", encoding));
+                               if (reader is XmlStreamReader)
+                                       parserContext.Encoding = ((XmlStreamReader) reader).Encoding;
+                               else
+                                       parserContext.Encoding = Encoding.Unicode;
+                       }
+
                        SetProperties (
                                XmlNodeType.XmlDeclaration, // nodeType
                                "xml", // name
index af99a466c64d85ebc010669e9e4a3e837852083f..cf8fad11c0fdada57e0454beec77490cc258123d 100644 (file)
@@ -1,3 +1,7 @@
+2005-12-09  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XmlTextReaderTests.cs : added test for Encoding property.
+
 2005-12-09  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlReaderCommonTests.cs : added tests for ReadToDescendant() and
index 253902f0063c2fd85409bd4714ef812c5b3a6feb..b32ebad63372ef1d073b75e222d2042183b701f4 100644 (file)
@@ -1153,5 +1153,15 @@ namespace MonoTests.System.Xml
                                XmlNodeType.Document, null);
                        xtr.Read ();
                }
+
+               [Test]
+               public void EncodingProperty ()
+               {
+                       string xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<root>\n<node>\nvalue\n</node>\n</root>";
+                       XmlTextReader xr = new XmlTextReader (xml, XmlNodeType.Document, null);
+                       AssertNull ("#1", xr.Encoding);
+                       xr.Read ();
+                       AssertEquals ("#2", Encoding.Unicode, xr.Encoding);
+               }
        }
 }