O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating Namespace Support

The Namespaces property provides read and write access to a value indicating if the writer will perform namespace support. This property is set to true by default.

Listing 10.21.
C#
XmlTextWriter writer = new XmlTextWriter("namespaces.xml");
writer.Namespaces = true;

writer.WriteElementString("po",
                          "test",
                          "http://www.fake.com");

VB
Dim writer As New XmlTextWriter("namespaces.xml")
writer.Namespaces = True
writer.WriteElementString("po",
                          "test",
                          "http://www.fake.com")

Output
<po:test xmlns:po="http://www.fake.com" />

If namespace support is turned off, then any attempts to declare a namespace will raise InvalidArgumentException. The Namespaces property must be set before any write operation has been executed. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required