共用方式為


XmlSerializerNamespaces 建構函式

定義

初始化 XmlSerializerNamespaces 類別的新執行個體。

多載

XmlSerializerNamespaces()

初始化 XmlSerializerNamespaces 類別的新執行個體。

XmlSerializerNamespaces(XmlSerializerNamespaces)

使用包含前置詞和命名空間配對集合之 XmlSerializerNamespaces 的指定執行個體,初始化 XmlSerializerNamespaces 類別的新執行個體。

XmlSerializerNamespaces(XmlQualifiedName[])

初始化 XmlSerializerNamespaces 類別的新執行個體。

XmlSerializerNamespaces()

初始化 XmlSerializerNamespaces 類別的新執行個體。

public:
 XmlSerializerNamespaces();
public XmlSerializerNamespaces ();
Public Sub New ()

範例

下列範例會建立 類別的 XmlSerializerNamespaces 實例,並將前置詞和命名空間組新增至 物件。

public:
   void CreateBook( String^ filename )
   {
      try
      {
         // Create instance of XmlSerializerNamespaces and add the namespaces.
         XmlSerializerNamespaces^ myNameSpaces = gcnew XmlSerializerNamespaces;
         myNameSpaces->Add( "BookName", "http://www.cpandl.com" );
         
         // Create instance of XmlSerializer and specify the type of object
         // to be serialized.
         XmlSerializer^ mySerializerObject =
            gcnew XmlSerializer( MyBook::typeid );

         TextWriter^ myWriter = gcnew StreamWriter( filename );
         // Create object to be serialized.
         MyBook^ myXMLBook = gcnew MyBook;

         myXMLBook->Author = "XMLAuthor";
         myXMLBook->BookName = "DIG THE XML";
         myXMLBook->Description = "This is a XML Book";

         MyPriceClass^ myBookPrice = gcnew 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: {0} occurred", e->Message );
      }
   }
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");
   }
}
Private Sub CreateBook(filename As String)
   Try
      ' Create instance of XmlSerializerNamespaces and add the namespaces.
      Dim myNameSpaces As New XmlSerializerNamespaces()
      myNameSpaces.Add("BookName", "http://www.cpandl.com")

      ' Create instance of XmlSerializer and specify the type of object;
      ' to be serialized.
      Dim mySerializerObject As New XmlSerializer(GetType(MyBook))

      Dim myWriter = New StreamWriter(filename)
      ' Create object to be serialized.
      Dim myXMLBook As New MyBook()

      myXMLBook.Author = "XMLAuthor"
      myXMLBook.BookName = "DIG THE XML"
      myXMLBook.Description = "This is a XML Book"

      Dim myBookPrice As New MyPriceClass()
      myBookPrice.Price = CDec(45.89)
      myBookPrice.Units = "$"
      myXMLBook.BookPrice = myBookPrice

      ' Serialize the object.
      mySerializerObject.Serialize(myWriter, myXMLBook, myNameSpaces)
      myWriter.Close()
   Catch e As Exception
      Console.WriteLine("Exception :" & e.Message & "Occurred")
   End Try
End Sub

適用於

XmlSerializerNamespaces(XmlSerializerNamespaces)

使用包含前置詞和命名空間配對集合之 XmlSerializerNamespaces 的指定執行個體,初始化 XmlSerializerNamespaces 類別的新執行個體。

public:
 XmlSerializerNamespaces(System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces);
public XmlSerializerNamespaces (System.Xml.Serialization.XmlSerializerNamespaces namespaces);
new System.Xml.Serialization.XmlSerializerNamespaces : System.Xml.Serialization.XmlSerializerNamespaces -> System.Xml.Serialization.XmlSerializerNamespaces
Public Sub New (namespaces As XmlSerializerNamespaces)

參數

namespaces
XmlSerializerNamespaces

XmlSerializerNamespaces 的執行個體,包含命名空間和前置詞配對。

範例

下列範例會建立兩 XmlQualifiedName 個 物件,並從中建立新的 XmlSerializerNamespaces 實例。

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

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

      array<XmlQualifiedName^>^ names = { q1, q2 };

      return gcnew XmlSerializerNamespaces( names );
   }
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);
}
Private Function CreateFromQNames() As XmlSerializerNamespaces
    Dim q1 As New XmlQualifiedName("money", "http://www.cohowinery.com")
    Dim q2 As New XmlQualifiedName("books", "http://www.cpandl.com")
    
    Dim names() As XmlQualifiedName =  {q1, q2}
    
    Return New XmlSerializerNamespaces(names)
End Function

適用於

XmlSerializerNamespaces(XmlQualifiedName[])

初始化 XmlSerializerNamespaces 類別的新執行個體。

public:
 XmlSerializerNamespaces(cli::array <System::Xml::XmlQualifiedName ^> ^ namespaces);
public XmlSerializerNamespaces (System.Xml.XmlQualifiedName[] namespaces);
new System.Xml.Serialization.XmlSerializerNamespaces : System.Xml.XmlQualifiedName[] -> System.Xml.Serialization.XmlSerializerNamespaces
Public Sub New (namespaces As XmlQualifiedName())

參數

namespaces
XmlQualifiedName[]

XmlQualifiedName 物件的陣列。

適用於