Assigns the XmlArrayAttribute to two arrays, and serializes a class instance that contains those arrays. : Attribute « XML « VB.Net Tutorial






Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization


Public Class MyClass1
    <XmlArrayAttribute("MyStrings")> Public MyStringArray() As String

    <XmlArrayAttribute(ElementName := "MyIntegers")>Public MyIntegerArray() As Integer
End Class


Public Class Run

    Public Shared Sub Main()
        Dim s As New XmlSerializer(GetType(MyClass1))
        Dim myWriter As New StreamWriter("yourName.xml")

        Dim class1 As New MyClass1()
        Dim myStrings() As String =  {"Hello", "World", "!"}
        class1.MyStringArray = myStrings
        Dim myIntegers() As Integer =  {1, 2, 3}
        class1.MyIntegerArray = myIntegers
        s.Serialize(myWriter, class1)
        myWriter.Close()
    End Sub
End Class








25.9.Attribute
25.9.1.Display all the attributes in the collection.
25.9.2.Creates an attribute and adds it to an XML document.
25.9.3.Assigns the XmlArrayAttribute to two arrays, and serializes a class instance that contains those arrays.
25.9.4.Remove an attribute from the document.
25.9.5.Adds an attribute to an element.
25.9.6.Get the value of the ISBN attribute.