XmlSerializerNamespaces.Add(String, String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Maklum balas
https://aka.ms/ContentUserFeedback.
Akan datang: Sepanjang 2024, kami akan menghentikan secara berperingkat Isu GitHub sebagai kaedah maklum balas untuk kandungan dan menggantikannya dengan sistem maklum balas baharu. Untuk mendapatkan maklumat lanjut lihat:Kirim dan lihat maklum balas untuk