XmlSerializerNamespaces.Add Method

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
)
public void Add (
	String prefix, 
	String ns
)
public function Add (
	prefix : String, 
	ns : String
)

Parameters

prefix

The prefix associated with an XML namespace.

ns

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;
}


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;     
} //AddNamespaces

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show: