Muokkaa

Jaa


XmlSerializerNamespaces.Add(String, String) Method

Definition

Adds a prefix and namespace pair to an XmlSerializerNamespaces object.

public:
 void Add(System::String ^ prefix, System::String ^ ns);
public void Add (string prefix, string ns);
public void Add (string prefix, string? ns);
member this.Add : string * string -> unit
Public Sub Add (prefix As String, ns As String)

Parameters

prefix
String

The prefix associated with an XML namespace.

ns
String

An XML namespace.

Examples

The following example creates an XmlSerializerNamespaces object, and adds three prefix and namespace pairs to it by calling the Add method.

private:
   XmlSerializerNamespaces^ AddNamespaces()
   {
      XmlSerializerNamespaces^ xmlNamespaces =
         gcnew 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;
   }
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;
}
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

Remarks

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

Any namespaces that you add must conform to the W3C Namespaces in XML specification.

Applies to