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
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기