[Xml] Fix GetAttribute to handle null namespaces properly, add unit test.
[mono.git] / mcs / class / System.XML / System.Xml / XmlTextReader2.cs
index 69ede0f7779e4039951b43ea008c991bac0baa15..b975f9849e384777d14b81a7282312e9ae175fea 100644 (file)
@@ -40,6 +40,19 @@ using Mono.Xml;
 
 namespace System.Xml
 {
+       // FIXME: this implementation requires somewhat significant change
+       // to expand entities and merge sequential text and entity references
+       // especially to handle whitespace-only entities (such as bug #372839).
+       //
+       // To do it, we have to read ahead the next node when the input is
+       // text, whitespace or significant whitespace and check if the next
+       // node is EntityReference. If it is entref, then it have to merge
+       // the input entity if it is a text.
+       //
+       // This "read ahead" operation may result in proceeding to the next
+       // element, which badly affects IXmlNamespaceResolverimplementation.
+       // So we cannot fix this in simple way.
+
        [PermissionSet (SecurityAction.InheritanceDemand, Unrestricted = true)]
        public class XmlTextReader : XmlReader,
                IXmlLineInfo, IXmlNamespaceResolver, IHasXmlParserContext
@@ -129,9 +142,9 @@ namespace System.Xml
                        source = new XmlTextReaderImpl (baseURI, xmlFragment, fragType, context);
                }
 
-               internal XmlTextReader (bool dummy, string url, XmlNodeType fragType, XmlParserContext context)
+               internal XmlTextReader (bool dummy, XmlResolver resolver, string url, XmlNodeType fragType, XmlParserContext context)
                {
-                       source = new XmlTextReaderImpl (dummy, url, fragType, context);
+                       source = new XmlTextReaderImpl (dummy, resolver, url, fragType, context);
                }
 
                private XmlTextReader (XmlTextReaderImpl entityContainer, bool insideAttribute)
@@ -580,19 +593,21 @@ namespace System.Xml
                public void ResetState ()
                {
                        if (entity != null)
-                               entity.ResetState ();
+                               CloseEntity ();
                        source.ResetState ();
                }
 
-               public override void ResolveEntity ()
+               public override
+               void ResolveEntity ()
                {
                        if (entity != null)
                                entity.ResolveEntity ();
                        else {
                                if (source.NodeType != XmlNodeType.EntityReference)
                                        throw new InvalidOperationException ("The current node is not an Entity Reference");
-                               XmlTextReaderImpl entReader = 
-                                       ParserContext.Dtd.GenerateEntityContentReader (source.Name, ParserContext);
+                               XmlTextReaderImpl entReader = null;
+                               if (ParserContext.Dtd != null)
+                                       entReader = ParserContext.Dtd.GenerateEntityContentReader (source.Name, ParserContext);
                                if (entReader == null)
                                        throw new XmlException (this as IXmlLineInfo, this.BaseURI, String.Format ("Reference to undeclared entity '{0}'.", source.Name));
                                if (entityNameStack == null)
@@ -619,7 +634,7 @@ namespace System.Xml
                        base.Skip ();
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public TextReader GetRemainder ()
                {
                        if (entity != null) {
@@ -635,7 +650,7 @@ namespace System.Xml
                        return true;
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public int ReadBase64 (byte [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -644,7 +659,7 @@ namespace System.Xml
                                return source.ReadBase64 (buffer, offset, length);
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public int ReadBinHex (byte [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -653,7 +668,7 @@ namespace System.Xml
                                return source.ReadBinHex (buffer, offset, length);
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public int ReadChars (char [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -663,7 +678,7 @@ namespace System.Xml
                }
 
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public override int ReadContentAsBase64 (byte [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -672,7 +687,7 @@ namespace System.Xml
                                return source.ReadContentAsBase64 (buffer, offset, length);
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public override int ReadContentAsBinHex (byte [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -681,7 +696,7 @@ namespace System.Xml
                                return source.ReadContentAsBinHex (buffer, offset, length);
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public override int ReadElementContentAsBase64 (byte [] buffer, int offset, int length)
                {
                        if (entity != null)
@@ -690,7 +705,7 @@ namespace System.Xml
                                return source.ReadElementContentAsBase64 (buffer, offset, length);
                }
 
-               [MonoTODO ("Check how expanded entity is handled here.")]
+               [MonoTODO] // FIXME: Check how expanded entity is handled here.
                public override int ReadElementContentAsBinHex (byte [] buffer, int offset, int length)
                {
                        if (entity != null)