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 | |
---|---|---|
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. |
Top
Properties
Name | Description | |
---|---|---|
Count | Gets the number of prefix and namespace pairs in the collection. |
Top
Methods
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.) |
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:
Create an XmlSerializerNamespaces instance.
Add each prefix and namespace pair that you want to the instance.
Apply the appropriate .NET attribute to each property or class that the XmlSerializer serializes into an XML document. The available attributes are:
Set the Namespace property of each attribute to one of the namespace values from the XmlSerializerNamespaces object.
Pass the XmlSerializerNamespaces to the Serialize method of the XmlSerializer.
Note: |
---|
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.