XmlSerializerNamespaces Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Contains the XML namespaces and prefixes that the XmlSerializer uses to generate qualified names in an XML-document instance.

Inheritance Hierarchy


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


Public Class XmlSerializerNamespaces
public class XmlSerializerNamespaces

The XmlSerializerNamespaces type exposes the following members.


Name Description
XmlSerializerNamespaces()()() Initializes a new instance of the XmlSerializerNamespaces class.
XmlSerializerNamespaces(array<XmlQualifiedName>[]()[]) Initializes a new instance of the XmlSerializerNamespaces class.
XmlSerializerNamespaces(XmlSerializerNamespaces) Infrastructure. Initializes a new instance of the XmlSerializerNamespaces class, using the specified instance of XmlSerializerNamespaces that contains the collection of prefix and namespace pairs.



Name Description
Count Gets the number of prefix and namespace pairs in the collection.



Name Description
Add Adds a prefix and namespace pair to an XmlSerializerNamespaces object.
Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
GetType Gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToArray Gets the array of prefix and namespace pairs in an XmlSerializerNamespaces object.
ToString Returns a string that represents the current object. (Inherited from Object.)



The XmlSerializerNamespaces contains a collection of XML namespaces, each with an associated prefix. The XmlSerializer uses an instance of the XmlSerializerNamespaces class to create qualified names in an XML document.

XML namespaces contained by the XmlSerializerNamespaces must conform to the www.w3.org specification, Namespaces in XML.

XML namespaces provide a way to qualify the names of XML elements and attributes in XML documents. A qualified name consists of a prefix and a local name, separated by a colon. The prefix functions only as a placeholder; it is mapped to a URI that specifies a namespace. The combination of the universally-managed URI namespace and the local name produces a name that is guaranteed to be universally unique.

To create qualified names in an XML document:

  1. Create an XmlSerializerNamespaces instance.

  2. Add each prefix and namespace pair that you want to the instance.

  3. Apply the appropriate .NET attribute to each property or class that the XmlSerializer serializes into an XML document. The available attributes are:

  1. Set the Namespace property of each attribute to one of the namespace values from the XmlSerializerNamespaces object.

  2. Pass the XmlSerializerNamespaces to the Serialize method of the XmlSerializer.


The creation of an empty namespace and prefix pair is not supported. That is, you cannot create a pair using the following code.

XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); 
ns.Add("", "");
Dim ns As XmlSerializerNamespaces ns = New XmlSerializerNamespaces()
ns.Add("", "")

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


System.Xml.Serialization Namespace