Freigeben über


XmlSerializerNamespaces Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.Xml.Serialization.XmlSerializerNamespaces

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

Syntax

'Declaration
Public Class XmlSerializerNamespaces
public class XmlSerializerNamespaces

The XmlSerializerNamespaces type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlSerializerNamespaces() Initializes a new instance of the XmlSerializerNamespaces class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlSerializerNamespaces(array<XmlQualifiedName[]) Initializes a new instance of the XmlSerializerNamespaces class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 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.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Count Gets the number of prefix and namespace pairs in the collection.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Add Adds a prefix and namespace pair to an XmlSerializerNamespaces object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 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.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToArray Gets the array of prefix and namespace pairs in an XmlSerializerNamespaces object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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.