Export (0) Print
Expand All

XmlSerializerNamespaces.Add Method

Adds a prefix-namespace pair to an XmlSerializerNamespaces object.

[Visual Basic]
Public Sub Add( _
   ByVal prefix As String, _
   ByVal ns As String _
)
[C#]
public void Add(
 string prefix,
 string ns
);
[C++]
public: void Add(
 String* prefix,
 String* ns
);
[JScript]
public function Add(
   prefix : String,
 ns : String
);

Parameters

prefix
The prefix associated with an XML namespace.
ns
An XML namespace.

Remarks

If you want the XmlSerializer to qualify the element and attribute names in an XML document, you must Add the prefix-namespace pairs to an XmlSerializerNamespaces object.

Any namespaces that you add must conform to the www.w3.org specification Namespaces in

XML.

Example

[Visual Basic, C#, C++] The following example creates an XmlSerializerNamespaces object, and adds three prefix-namespace pairs to it by calling the Add method.

[Visual Basic] 
Private Function AddNamespaces() As XmlSerializerNamespaces
    Dim xmlNamespaces As 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
End Function


[C#] 
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;
}


[C++] 
private:
XmlSerializerNamespaces* AddNamespaces()
{
   XmlSerializerNamespaces* xmlNamespaces = 
   new XmlSerializerNamespaces();

   // Add three prefix-namespace pairs.
   xmlNamespaces->Add(S"money", S"http://www.cpandl.com");
   xmlNamespaces->Add(S"books", S"http://www.cohowinery.com");
   xmlNamespaces->Add(S"software", S"http://www.microsoft.com");

   return xmlNamespaces;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlSerializerNamespaces Class | XmlSerializerNamespaces Members | System.Xml.Serialization Namespace

Show:
© 2014 Microsoft