XmlSerializerNamespaces.Add Method (String, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds a prefix and namespace pair to an XmlSerializerNamespaces object.

Namespace:   System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public void Add(
	string prefix,
	string ns


Type: System.String

The prefix associated with an XML namespace.

Type: System.String

An XML namespace.

If you want the XmlSerializer to qualify the element and attribute names in an XML document, you must Add the prefix and namespace pairs to an XmlSerializerNamespaces object.

Any namespaces that you add must conform to the www.w3.org specification Namespaces in XML.

The following example creates an XmlSerializerNamespaces object, and adds three prefix and namespace pairs to it by calling the Add method.

private XmlSerializerNamespaces AddNamespaces()
   XmlSerializerNamespaces xmlNamespaces = 
   new XmlSerializerNamespaces();

   // Add three prefix-namespace pairs.
   xmlNamespaces.Add("money", "http://www.cpandl.com");
   xmlNamespaces.Add("books", "http://www.cohowinery.com");
   xmlNamespaces.Add("software", "http://www.microsoft.com");

   return xmlNamespaces;

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top