Ich stelle mich wohl leider zu blöde an.
Ich wollte dein Beispiel nachbauen, aber ich bekomme es leider nicht richtig hin.
Es wirkt einfach nicht.
Ich denke ich mache noch irgendwas falsch und merke es leider nicht.
Public Class Form1
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Module1.Test1()
End Sub
End Class Module Module1
Dim Instance_Class1 As New Class1
Sub Test1()
Dim NewItem As New Class2
NewItem.Hinweis = "Hinweis als String"
NewItem.Höhe = 3.67
NewItem.Name = "Test"
NewItem.Symbol = "keines"
NewItem.Time = Date.Now
Instance_Class1.Wegpunkte.Add(NewItem)
Instance_Class1.Save()
End Sub
End Module Public Class Class1
Public Wegpunkte As New List(Of Class2)
Private Sub GetPathname(ByRef strPathnameOUT As String)
Dim strFullyQualifiedName As String = Nothing
Dim strName As String = Nothing
Dim strBasePath As String = Nothing
Dim intLength_FullyQualifiedName As Integer = Nothing
Dim intLength_Name As Integer = Nothing
Dim intLength_BasePath As Integer = Nothing
strPathnameOUT = Nothing
strFullyQualifiedName = _
System.Reflection.Assembly.GetExecutingAssembly.ManifestModule.FullyQ_
ualifiedName
strName = _
System.Reflection.Assembly.GetExecutingAssembly.ManifestModule.Name
intLength_FullyQualifiedName = strFullyQualifiedName.Length
intLength_Name = strName.Length
intLength_BasePath = intLength_FullyQualifiedName - intLength_Name
strBasePath = Microsoft.VisualBasic.Strings.Left(strFullyQualifiedName, _
intLength_BasePath)
strPathnameOUT = strBasePath & "1.xml"
End Sub
Function Save() As Boolean
Dim strPathname As String = Nothing
Dim StreamWriter As System.IO.StreamWriter = Nothing
Dim Serializer As System.Xml.Serialization.XmlSerializer = _
Nothing
'Pfadname herausfinden
Me.GetPathname(strPathname)
Try
StreamWriter = New System.IO.StreamWriter(strPathname)
Serializer = New System.Xml.Serialization.XmlSerializer( _
GetType(List(Of Class2) ) )
Catch ex As Exception
goto ErrorExit
End Try
Try
Serializer.Serialize(StreamWriter, Wegpunkte)
StreamWriter.Close()
Catch ex As Exception
goto ErrorExit
End Try
return True
ErrorExit:
return False
End Function
End Class <System.Xml.Serialization.XmlType("wpt")> _
Public Class Class2
<System.Xml.Serialization.XmlElement("name", order:=2)> _
Public Name As String
<System.Xml.Serialization.XmlElement("ele", order:=0)> _
Public Höhe As Double
<System.Xml.Serialization.XmlElement("time", order:=1)> _
Public Time As Date
<System.Xml.Serialization.XmlElement("cmt", order:=3)> _
Public Hinweis As String
<System.Xml.Serialization.XmlElement("sym", order:=4)> _
Public Symbol As String
End Class Als Datei bekomme ich nun dieses:
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfWpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" _
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wpt>
<ele>3.67</ele>
<time>2015-02-24T19:01:31.1623919+01:00</time>
<name>Test</name>
<cmt>Hinweis als String</cmt>
<sym>keines</sym>
</wpt>
</ArrayOfWpt> Was mache ich falsch? Ich frage weil das mit XmlElement über der Liste hat überhaupt nichts bewirkt.
Das mit dem XmlRoot hatte auch nichts bewirkt.
Wie benenne ich <ArrayOfWpt ... um?
0 |