XmlSerializerNamespaces Constructors

Definition

Initializes a new instance of the XmlSerializerNamespaces class.

Overloads

XmlSerializerNamespaces()

Initializes a new instance of the XmlSerializerNamespaces class.

XmlSerializerNamespaces(XmlSerializerNamespaces)

Initializes a new instance of the XmlSerializerNamespaces class, using the specified instance of XmlSerializerNamespaces containing the collection of prefix and namespace pairs.

XmlSerializerNamespaces(XmlQualifiedName[])

Initializes a new instance of the XmlSerializerNamespaces class.

XmlSerializerNamespaces()

Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs

Initializes a new instance of the XmlSerializerNamespaces class.

public XmlSerializerNamespaces ();

Examples

The following example creates an instance of the XmlSerializerNamespaces class, and adds a prefix and namespace pair to the object.

private void CreateBook(string filename)
{
   try
   {
      // Create instance of XmlSerializerNamespaces and add the namespaces.
      XmlSerializerNamespaces myNameSpaces = new XmlSerializerNamespaces();
      myNameSpaces.Add("BookName", "http://www.cpandl.com");
   
      // Create instance of XmlSerializer and specify the type of object
      // to be serialized.
      XmlSerializer mySerializerObject = 
         new XmlSerializer(typeof(MyBook));

      TextWriter myWriter = new StreamWriter(filename);
      // Create object to be serialized.
      MyBook myXMLBook = new MyBook();
   
      myXMLBook.Author = "XMLAuthor";
      myXMLBook.BookName = "DIG THE XML";
      myXMLBook.Description = "This is a XML Book";

      MyPriceClass myBookPrice = new MyPriceClass();
      myBookPrice.Price = (decimal) 45.89;
      myBookPrice.Units = "$";
      myXMLBook.BookPrice = myBookPrice;

      // Serialize the object.
      mySerializerObject.Serialize(myWriter, myXMLBook,myNameSpaces);
      myWriter.Close();
   }
   catch(Exception e)
   {
      Console.WriteLine("Exception :" + e.Message + "Occurred");
   }
}

Applies to

.NET 9 та інші версії
Продукт Версії
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

XmlSerializerNamespaces(XmlSerializerNamespaces)

Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs

Initializes a new instance of the XmlSerializerNamespaces class, using the specified instance of XmlSerializerNamespaces containing the collection of prefix and namespace pairs.

public XmlSerializerNamespaces (System.Xml.Serialization.XmlSerializerNamespaces namespaces);

Parameters

namespaces
XmlSerializerNamespaces

An instance of the XmlSerializerNamespaces containing the namespace and prefix pairs.

Examples

The following example creates two XmlQualifiedName objects, and creates a new XmlSerializerNamespaces instance from them.

private XmlSerializerNamespaces CreateFromQNames()
{
   XmlQualifiedName q1 =
   new XmlQualifiedName("money", "http://www.cohowinery.com");

   XmlQualifiedName q2 =
   new XmlQualifiedName("books", "http://www.cpandl.com");

   XmlQualifiedName[] names = {q1, q2};

   return new XmlSerializerNamespaces(names);
}

Applies to

.NET 9 та інші версії
Продукт Версії
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

XmlSerializerNamespaces(XmlQualifiedName[])

Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs
Source:
XmlSerializerNamespaces.cs

Initializes a new instance of the XmlSerializerNamespaces class.

public XmlSerializerNamespaces (System.Xml.XmlQualifiedName[] namespaces);

Parameters

namespaces
XmlQualifiedName[]

An array of XmlQualifiedName objects.

Applies to

.NET 9 та інші версії
Продукт Версії
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0