This one has me really stumped. Here is my XML document contents. The real file has hundreds of <logentry></logentry> sets. I've simplified the file in order to get the serialization working:
<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry
revision="2444">
<author>pgs</author>
<date>2014-06-30T18:32:28.636507Z</date>
<paths>
<path
kind=""
action="M">/myPath/bin/Debug/myFile.dll</path>
<path
kind=""
action="M">/myPath/bin/Debug/myFile.pdb</path>
<path
kind=""
action="M">/myPath/obj/Debug/myFile.dll</path>
<path
kind=""
action="M">/myPath/obj/Debug/myFile.pdb</path>
</paths>
<msg>No changes.
</msg>
</logentry>
</log>
Here is what I perceive to be the vb.net code to describe this XML document:
<XmlRoot("log")> _
Public Class Log
<XmlArray(ElementName:="logentry")> _
Public Property Logentries As New List ( Of Logentry )
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
<XmlRoot(ElementName:="path")> _
Public Class Path
<XmlAttribute("kind")> _
Public Property Path_Kind As String
<XmlAttribute("action")> _
Public Property Path_Action As String
'
'NOTE: I don't know how to code this. If you look at the XML file, this is a type of entry that is there:
' <path
' kind=""
' action="M">/myPath/bin/Debug/myFile.dll</path>
'
' kind and action are attributes of the <path, but what do you call the item between the > and the </path> that begins with /mypath???
'
<XmlElement("value")> _
Public Property Path_Value As String
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
<XmlRoot(Elementname:="logentry")> _
Public Class Logentry
<XmlAttribute("revision")> _
Public Property Logentry_Revision As String
<XmlElement("author")> _
Public Property Logentry_Author As String
<XmlElement("date")> _
Public Property Logentry_Date As String
<XmlArray(ElementName:="paths")>
<XmlArrayItem(ElementName:="path")> _
Public Property Logentry_Paths As New List ( Of Path )
<XmlElement("msg")> _
Public Property Logentry_Msg As String
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
Here is my deserialization function. I took a look at oLog.Count after the deserialize and it is 0. What am I doing wrong??
Public Function LoadSVNLog ( ByVal fileName As String ) As Log
Try
Dim fileStream As Stream = New FileStream ( fileName, FileMode.Open, FileAccess.Read, FileShare.Read )
Dim numLength As Integer = fileStream.Length
fileStream.Position = 0
Using fileStream
Dim deserializer As XmlSerializer = New XmlSerializer ( GetType(Log) )
Dim oLog As Log = DirectCast ( deserializer.Deserialize ( fileStream ), Log )
Return oLog
End Using
Catch Err As Exception
moTRSLib.LogMessage(TRSLibrary.Net.TRSLib.LOGLEVEL.CRITICAL, "Main - Error: #1#", Err.Message)
End Try
End Function
And here is the call to it:
Dim oLog As Log = LoadSVNLog ( "C:\Personify\stripped_personify_svn_log.xml" )
For Each oL As Logentry In oLog.Logentries
Dim strRevision As String = oL.Logentry_Revision
Dim strAuthor As String = oL.Logentry_Author
Dim strDate As String = oL.Logentry_Date
Dim strLogMsg As String = oL.Logentry_Msg
For Each oP As Path In oL.Logentry_Paths
Dim strKind As String = oP.Path_Kind
Dim strAction As String = oP.Path_Action
Dim strFile As String = oP.Path_Value
Next
Next
But, since the oLog.Count = 0, nothing happens in the "For Each..."
Since I had the problem with identifying the <path... stuff, I ran a modified version of this that didn't have the <paths> and <path> at all and still the oLog.Count was 0
Thank you in advance,
Jerry Scannell
<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry
revision="2444">
<author>pgs</author>
<date>2014-06-30T18:32:28.636507Z</date>
<paths>
<path
kind=""
action="M">/myPath/bin/Debug/myFile.dll</path>
<path
kind=""
action="M">/myPath/bin/Debug/myFile.pdb</path>
<path
kind=""
action="M">/myPath/obj/Debug/myFile.dll</path>
<path
kind=""
action="M">/myPath/obj/Debug/myFile.pdb</path>
</paths>
<msg>No changes.
</msg>
</logentry>
</log>
Here is what I perceive to be the vb.net code to describe this XML document:
<XmlRoot("log")> _
Public Class Log
<XmlArray(ElementName:="logentry")> _
Public Property Logentries As New List ( Of Logentry )
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
<XmlRoot(ElementName:="path")> _
Public Class Path
<XmlAttribute("kind")> _
Public Property Path_Kind As String
<XmlAttribute("action")> _
Public Property Path_Action As String
'
'NOTE: I don't know how to code this. If you look at the XML file, this is a type of entry that is there:
' <path
' kind=""
' action="M">/myPath/bin/Debug/myFile.dll</path>
'
' kind and action are attributes of the <path, but what do you call the item between the > and the </path> that begins with /mypath???
'
<XmlElement("value")> _
Public Property Path_Value As String
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
<XmlRoot(Elementname:="logentry")> _
Public Class Logentry
<XmlAttribute("revision")> _
Public Property Logentry_Revision As String
<XmlElement("author")> _
Public Property Logentry_Author As String
<XmlElement("date")> _
Public Property Logentry_Date As String
<XmlArray(ElementName:="paths")>
<XmlArrayItem(ElementName:="path")> _
Public Property Logentry_Paths As New List ( Of Path )
<XmlElement("msg")> _
Public Property Logentry_Msg As String
Public Sub New()
'do stuff here if you need to, but try to relegate anything important to a constructor that takes a parameter accommodating said important behavior
End Sub
End Class
Here is my deserialization function. I took a look at oLog.Count after the deserialize and it is 0. What am I doing wrong??
Public Function LoadSVNLog ( ByVal fileName As String ) As Log
Try
Dim fileStream As Stream = New FileStream ( fileName, FileMode.Open, FileAccess.Read, FileShare.Read )
Dim numLength As Integer = fileStream.Length
fileStream.Position = 0
Using fileStream
Dim deserializer As XmlSerializer = New XmlSerializer ( GetType(Log) )
Dim oLog As Log = DirectCast ( deserializer.Deserialize ( fileStream ), Log )
Return oLog
End Using
Catch Err As Exception
moTRSLib.LogMessage(TRSLibrary.Net.TRSLib.LOGLEVEL.CRITICAL, "Main - Error: #1#", Err.Message)
End Try
End Function
And here is the call to it:
Dim oLog As Log = LoadSVNLog ( "C:\Personify\stripped_personify_svn_log.xml" )
For Each oL As Logentry In oLog.Logentries
Dim strRevision As String = oL.Logentry_Revision
Dim strAuthor As String = oL.Logentry_Author
Dim strDate As String = oL.Logentry_Date
Dim strLogMsg As String = oL.Logentry_Msg
For Each oP As Path In oL.Logentry_Paths
Dim strKind As String = oP.Path_Kind
Dim strAction As String = oP.Path_Action
Dim strFile As String = oP.Path_Value
Next
Next
But, since the oLog.Count = 0, nothing happens in the "For Each..."
Since I had the problem with identifying the <path... stuff, I ran a modified version of this that didn't have the <paths> and <path> at all and still the oLog.Count was 0
Thank you in advance,
Jerry Scannell