[Mono-dev] XmlDocument.CreateElement

Vladimir Giszpenc vladimir.giszpenc at gmail.com
Thu May 10 06:52:40 EDT 2007


Hi,

I don't have Windows so I could not test this on the .Net CLR but the
behavior I am getting seems weird.  If I call
xmlDocument.CreateElement("foo:bar"), the "foo" gets removed if I don't pass
in the namespace as the second parameter.  Is this by design?

See attachment for example...

Thanks,

Vlad

using System.Xml;

public class Test
{
  static void Main()
  {
    XmlDocument doc= new XmlDocument();
    XmlElement header = doc.CreateElement("foobar");
    header.SetAttribute ("xmlns:foo", "http://foo.bar.org/XMLSchema");

    //The name of this element has a namespace in it, but apparently
that is not enough
    //because it is removed in the saved file.
    XmlElement foobar = doc.CreateElement ("foo:bar");

    XmlElement ok = doc.CreateElement ("foo:ok",
"http://foo.bar.org/XMLSchema");
    header.AppendChild(foobar);
    header.AppendChild(ok);
    doc.AppendChild(header);
    doc.Save("foobar.xml");
  }
}



More information about the Mono-devel-list mailing list