|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
default namespaceHi 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 Peter Ramsebner wrote:
> does anybody know how to generate an attribute for the default namespace Usually you do create such namespace declarations yourself, rather you > like: > xmlns="http://www.xxx.com/....." 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. |
|||||||||||||||||||||||