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 ως μηχανισμό ανάδρασης για το περιεχόμενο και θα το αντικαταστήσουμε με ένα νέο σύστημα ανάδρασης. Για περισσότερες πληροφορίες, ανατρέξτε στο θέμα:Υποβολή και προβολή σχολίων για