[Mono-list] xml bug?

David Sheldon dave-monolist@earth.li
Mon, 19 Jan 2004 23:13:19 +0000


On Mon, Jan 19, 2004 at 09:06:16PM +0100, Daniel Pecos wrote:
> Hi!
> 
> I have found an issue that I don't know if it's an error or it is ok:
> when I add an attribute named "xmlns" to an XmlElement, then all
> childs that were appended to it or those that will be, all have
> the same attribute but without content, and RemoveAttribute ("xmlns")
> does not work.


We should have rejected your XML, as you are trying to add more than one
top-level element (document element) to your document. The fact that we
don't do so is a bug. 

Now, as for the xmlns, xmlns is a special attribute, setting 
the xmlns attribute doesn't really do anything for the infoset, and the
b2 element is created in the null namespace. This is why the serialiser 
puts the xmlns="" on b2, that is so that b2 is in the namespace it was
created in. 

The correct way would be to create the b and b2 elements in the probe
namespace. This way the document you serialise is what you wanted, and
you have done it correctly.

using System;
using System.Xml;

namespace p {
   public class m {
      public static void Main (string [] args) {

         XmlDocument x = new XmlDocument ();
         XmlElement a = x.CreateElement ("a");
         XmlElement b = x.CreateElement ("b", "probe");
         x.AppendChild (a);
         a.AppendChild (b);
         XmlElement b2 = x.CreateElement ("b2", "probe");                           
         b.AppendChild (b2);

         Console.WriteLine (x.InnerXml);
      }
   }
}

Interestingly, your code works under MS .NET. I only need to make the
change "a.AppendChild (b);" instead of "x.AppendChild (b);".

Eno, what do you think we should do about this?

David



-- 
And it should be the law: If you use the word `paradigm' without knowing
what the dictionary says it means, you go to jail.  No exceptions.
		-- David Jones