Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlSerializerNamespaces::Add Method (String^, String^)

 

Adds a prefix and namespace pair to an XmlSerializerNamespaces object.

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

public:
void Add(
	String^ prefix,
	String^ ns
)

Parameters

prefix
Type: System::String^

The prefix associated with an XML namespace.

ns
Type: System::String^

An XML namespace.

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 www.w3.org specification Namespaces in XML.

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;
   }

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft