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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應