[Mono-list] XmlWriter failing to write xmlns declaration

Atsushi Eno atsushieno at veritas-vos-liberabit.com
Thu Jun 16 02:20:06 EDT 2011


Because you have wrong values for namespace prefix?

Next time, come up with runnable example like this. This verifies that xmlns
output works:

--------
using System;
using System.Xml;

public class X
{
         public static void Main ()
         {
                 string NCXNamespace = "nc";
                 string NCXNamespaceURI = "urn:foo";

                 var writer = XmlWriter.Create (Console.Out);
                 writer.WriteStartElement ("foo");
                 writer.WriteAttributeString("xmlns", NCXNamespace,
                         "http://www.w3.org/2000/xmlns/", NCXNamespaceURI);
                 writer.Close ();
         }
}

Atsushi Eno

(2011/06/16 4:35), tferch wrote:
> Using System.Xml.XmlWriter, I had a strange problem with writing the
> namespace declaration into the file. The line:
>
> writer.WriteAttributeString("xmlns", NCXNamespace,
>http://www.w3.org/2000/xmlns/”, NCXNamespaceURI);
>
> was crashing with the exception:
> "Invalid attribute namespace for namespace declaration."
>
> It would appear that this exception should only be thrown if the namespace
> URI does not match the proper string, but the provided string
> (“http://www.w3.org/2000/xmlns/”) should be the proper match.
>
> Any insights on why this was occurring?
>
> --
> View this message in context: http://mono.1490590.n4.nabble.com/XmlWriter-failing-to-write-xmlns-declaration-tp3600347p3600347.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list