XmlSerializerNamespaces Class

July 28, 2014

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

System.Object
  System.Xml.Serialization.XmlSerializerNamespaces

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

'Declaration
Public Class XmlSerializerNamespaces

The XmlSerializerNamespaces type exposes the following members.

  NameDescription
Public methodXmlSerializerNamespacesInitializes a new instance of the XmlSerializerNamespaces class.
Public methodXmlSerializerNamespaces(XmlQualifiedName())Initializes a new instance of the XmlSerializerNamespaces class.
Public methodXmlSerializerNamespaces(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.
Top

  NameDescription
Public propertyCountGets the number of prefix and namespace pairs in the collection.
Top

  NameDescription
Public methodAddAdds a prefix and namespace pair to an XmlSerializerNamespaces object.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToArrayGets the array of prefix and namespace pairs in an XmlSerializerNamespaces object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote:

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

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2014 Microsoft