Home All Groups Group Topic Archive Search About

default namespace

Author
6 Nov 2007 2:54 PM
Peter Ramsebner
Hi all,

does anybody know how to generate an attribute for the default namespace
like:
xmlns="http://www.xxx.com/....."

I have tried something like this:
myWriter.WriteAttributeString("xmlns", http://www.xxx.com/....)
I get the message:

"Das Präfix '' kann nicht von '' in 'http://www.ixxx.com/....'innerhalb
desselben Startelementtags neu definiert werden."

Thanks for any help

Peter

Author
6 Nov 2007 3:06 PM
Martin Honnen
Peter Ramsebner wrote:

> does anybody know how to generate an attribute for the default namespace
> like:
>  xmlns="http://www.xxx.com/....."

Usually you do create such namespace declarations yourself, rather you
write the elements in the correct namespace and then the serializer
automatically outputs the namespace declaration itself e.g. this code

       const string ns = "http://example.com/2007/ns1";
       using (XmlWriter writer = XmlWriter.Create(Console.Out))
       {
         writer.WriteStartElement("root", ns);
         writer.WriteElementString("foo", ns, "example");
         writer.WriteElementString("bar", ns, "example 2");
         writer.WriteEndElement();
       }

generates this XML:
<root xmlns="http://example.com/2007/ns1"><foo>example</foo><bar>example
2</bar></root>

So make sure you write out elements in the namespace they belong to,
that way you will get namespace declarations generated.


--

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/
Author
8 Nov 2007 12:44 PM
Peter Ramsebner
Thanks, but there are still more problems to solve...

Peter
Author
8 Nov 2007 1:16 PM
Martin Honnen
Peter Ramsebner wrote:
> Thanks, but there are still more problems to solve...

We can certainly help solving if you describe what XML you want to create.


--

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

AddThis Social Bookmark Button