當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET XmlAttributeAttribute構造函數代碼示例

本文整理匯總了VB.NET中System.Xml.Serialization.XmlAttributeAttribute.XmlAttributeAttribute構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlAttributeAttribute構造函數的具體用法?VB.NET XmlAttributeAttribute怎麽用?VB.NET XmlAttributeAttribute使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Xml.Serialization.XmlAttributeAttribute的用法示例。


在下文中一共展示了XmlAttributeAttribute構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Student

' 導入命名空間
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

' This is the class that will be serialized.
Public Class Student
   Public StudentName As String
   Public StudentNumber As Integer
End Class

Public Class Book
   Public BookName As String
   Public BookNumber As Integer
End Class

Public Class XMLAttributeAttribute_ctr1

   Public Shared Sub Main()
      Dim myAttribute As New XMLAttributeAttribute_ctr1()
      myAttribute.SerializeObject("Student.xml", "Book.xml")
   End Sub

   Public Sub SerializeObject(studentFilename As String, bookFilename As String)
      Dim mySerializer As XmlSerializer
      Dim writer As TextWriter

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlAttributeOverrides As New XmlAttributeOverrides()
      Dim myXmlAttributes As New XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property of the XmlAttributes object.
      Dim myXmlAttributeAttribute As New XmlAttributeAttribute()
      myXmlAttributeAttribute.AttributeName = "Name"
      myXmlAttributes.XmlAttribute = myXmlAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlAttributeOverrides.Add(GetType(Student), "StudentName", myXmlAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Student), myXmlAttributeOverrides)

      writer = New StreamWriter(studentFilename)

      ' Create an instance of the class that will be serialized.
      Dim myStudent As New Student()

      ' Set the Name property, which will be generated as an XML attribute. 
      myStudent.StudentName = "James"
      myStudent.StudentNumber = 1
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myStudent)
      writer.Close()

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlBookAttributeOverrides As New XmlAttributeOverrides()
      Dim myXmlBookAttributes As New XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property of the XmlAttributes object.
      Dim myXmlBookAttributeAttribute As New XmlAttributeAttribute("Name")
      myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlBookAttributeOverrides.Add(GetType(Book), "BookName", myXmlBookAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Book), myXmlBookAttributeOverrides)

      writer = New StreamWriter(bookFilename)

      ' Create an instance of the class that will be serialized.
      Dim myBook As New Book()

      ' Set the Name property, which will be generated as an XML attribute.
      myBook.BookName = ".NET"
      myBook.BookNumber = 10
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myBook)
      writer.Close()
   End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System.Xml.Serialization,代碼行數:81,代碼來源:XmlAttributeAttribute


注:本文中的System.Xml.Serialization.XmlAttributeAttribute.XmlAttributeAttribute構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。