[Mono-dev] XmlDocument.CreateElement

Atsushi Eno atsushi at ximian.com
Sat May 12 06:05:18 EDT 2007


Hi,

Yes, by design. Note that since you didn't specify namespace URI
for any of the elements you created, their namespaces are empty.
Without namespace URI, elements and attributes are not allowed to
have prefixes by "Namespaces in XML" specification.

XmlDocument does not support namespace-less documents unlike
XmlTextReader (which has Namespaces property).

(The same behavior as .NET.)

Atsushi Eno

Vladimir Giszpenc wrote:
> 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");
>   }
> }
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 




More information about the Mono-devel-list mailing list