Do you have a vb.net class which matches your xml schema? If not, you can follow this post to generate one https://stackoverflow.com/a/17315863/832052.
The classes should look like this:
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)> _
Partial Public Class Document
Private pointRecordField() As DocumentPointRecord
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("PointRecord")> _
Public Property PointRecord() As DocumentPointRecord()
Get
Return Me.pointRecordField
End Get
Set(value As DocumentPointRecord())
Me.pointRecordField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class DocumentPointRecord
Private nameField As String
Private codeField As String
Private methodField As String
Private classificationField As String
Private deletedField As Boolean
Private eCEFDeltasField As DocumentPointRecordECEFDeltas
Private idField As Byte
Private timeStampField As Date
'''<remarks/>
Public Property Name() As String
Get
Return Me.nameField
End Get
Set(value As String)
Me.nameField = value
End Set
End Property
'''<remarks/>
Public Property Code() As String
Get
Return Me.codeField
End Get
Set(value As String)
Me.codeField = value
End Set
End Property
'''<remarks/>
Public Property Method() As String
Get
Return Me.methodField
End Get
Set(value As String)
Me.methodField = value
End Set
End Property
'''<remarks/>
Public Property Classification() As String
Get
Return Me.classificationField
End Get
Set(value As String)
Me.classificationField = value
End Set
End Property
'''<remarks/>
Public Property Deleted() As Boolean
Get
Return Me.deletedField
End Get
Set(value As Boolean)
Me.deletedField = value
End Set
End Property
'''<remarks/>
Public Property ECEFDeltas() As DocumentPointRecordECEFDeltas
Get
Return Me.eCEFDeltasField
End Get
Set(value As DocumentPointRecordECEFDeltas)
Me.eCEFDeltasField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ID() As Byte
Get
Return Me.idField
End Get
Set(value As Byte)
Me.idField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property TimeStamp() As Date
Get
Return Me.timeStampField
End Get
Set(value As Date)
Me.timeStampField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class DocumentPointRecordECEFDeltas
Private deltaXField As DocumentPointRecordECEFDeltasDeltaX
Private deltaYField As DocumentPointRecordECEFDeltasDeltaY
Private deltaZField As DocumentPointRecordECEFDeltasDeltaZ
'''<remarks/>
Public Property DeltaX() As DocumentPointRecordECEFDeltasDeltaX
Get
Return Me.deltaXField
End Get
Set(value As DocumentPointRecordECEFDeltasDeltaX)
Me.deltaXField = value
End Set
End Property
'''<remarks/>
Public Property DeltaY() As DocumentPointRecordECEFDeltasDeltaY
Get
Return Me.deltaYField
End Get
Set(value As DocumentPointRecordECEFDeltasDeltaY)
Me.deltaYField = value
End Set
End Property
'''<remarks/>
Public Property DeltaZ() As DocumentPointRecordECEFDeltasDeltaZ
Get
Return Me.deltaZField
End Get
Set(value As DocumentPointRecordECEFDeltasDeltaZ)
Me.deltaZField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class DocumentPointRecordECEFDeltasDeltaX
Private valueField As Decimal
Private inToleranceField As String
'''<remarks/>
Public Property Value() As Decimal
Get
Return Me.valueField
End Get
Set(value As Decimal)
Me.valueField = value
End Set
End Property
'''<remarks/>
Public Property InTolerance() As String
Get
Return Me.inToleranceField
End Get
Set(value As String)
Me.inToleranceField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class DocumentPointRecordECEFDeltasDeltaY
Private valueField As Decimal
Private inToleranceField As String
'''<remarks/>
Public Property Value() As Decimal
Get
Return Me.valueField
End Get
Set(value As Decimal)
Me.valueField = value
End Set
End Property
'''<remarks/>
Public Property InTolerance() As String
Get
Return Me.inToleranceField
End Get
Set(value As String)
Me.inToleranceField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class DocumentPointRecordECEFDeltasDeltaZ
Private valueField As Decimal
Private inToleranceField As String
'''<remarks/>
Public Property Value() As Decimal
Get
Return Me.valueField
End Get
Set(value As Decimal)
Me.valueField = value
End Set
End Property
'''<remarks/>
Public Property InTolerance() As String
Get
Return Me.inToleranceField
End Get
Set(value As String)
Me.inToleranceField = value
End Set
End Property
End Class
Now that you have a class in vb.net, you can serialize and deserialize your xml document to an instance of the class.
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Sub Main()
Dim s = New XmlSerializer(GetType(Document))
Dim d As Document
' use your filename here
Using sr = New StreamReader("document.xml")
d = CType(s.Deserialize(sr), Document)
End Using
For Each pr In d.PointRecord
Console.WriteLine("Point Record ID: {0} Time Stamp: {1}",
pr.ID, pr.TimeStamp)
Console.WriteLine(" Name: {0}",
pr.Name)
Console.WriteLine(" Code: {0}",
pr.Code)
Console.WriteLine(" Method: {0}",
pr.Method)
Console.WriteLine(" Classication: {0}",
pr.Classification)
Console.WriteLine(" Deleted: {0}",
pr.Deleted)
Console.WriteLine(" ECFDeltas-")
Console.WriteLine(" DeltaX: {0:0.000000000} In Tolerance: {1}",
pr.ECEFDeltas.DeltaX.Value, pr.ECEFDeltas.DeltaX.InTolerance)
Console.WriteLine(" DeltaY: {0:0.000000000} In Tolerance: {1}",
pr.ECEFDeltas.DeltaY.Value, pr.ECEFDeltas.DeltaY.InTolerance)
Console.WriteLine(" DeltaZ: {0:0.000000000} In Tolerance: {1}",
pr.ECEFDeltas.DeltaZ.Value, pr.ECEFDeltas.DeltaZ.InTolerance)
Next
Console.ReadLine()
End Sub
I added another <PointRecord ID="00000050" TimeStamp="2017-03-03T09:39:54">
node to generate the model with an array of PointRecord
, assuming you have this.
<Document>
<PointRecord ID="00000050" TimeStamp="2017-03-03T09:39:54">
<Name>WF2510</Name>
<Code>EOC RECT 6/</Code>
<Method>StaticObservation</Method>
<Classification>Normal</Classification>
<Deleted>false</Deleted>
<ECEFDeltas>
<DeltaX>
<Value>-14179.040909261</Value>
<InTolerance>True</InTolerance>
</DeltaX>
<DeltaY>
<Value>-3572.6636230592</Value>
<InTolerance>True</InTolerance>
</DeltaY>
<DeltaZ>
<Value>-8319.8607607852</Value>
<InTolerance>False</InTolerance>
</DeltaZ>
</ECEFDeltas>
</PointRecord>
<PointRecord ID="00000051" TimeStamp="2017-03-03T09:39:54">
<Name>WF2510</Name>
<Code>EOC RECT 6/</Code>
<Method>StaticObservation</Method>
<Classification>Normal</Classification>
<Deleted>false</Deleted>
<ECEFDeltas>
<DeltaX>
<Value>-14179.040909261</Value>
<InTolerance>True</InTolerance>
</DeltaX>
<DeltaY>
<Value>-3572.6636230592</Value>
<InTolerance>True</InTolerance>
</DeltaY>
<DeltaZ>
<Value>-8319.8607607852</Value>
<InTolerance>False</InTolerance>
</DeltaZ>
</ECEFDeltas>
</PointRecord>
</Document>
When testing, my xml doc had two PointRecords
. The output of the program:
Point Record ID: 50 Time Stamp: 3/3/2017 9:39:54 AM
Name: WF2510
Code: EOC RECT 6/
Method: StaticObservation
Classication: Normal
Deleted: False
ECFDeltas-
DeltaX: -14179.040909261 In Tolerance: True
DeltaY: -3572.663623059 In Tolerance: True
DeltaZ: -8319.860760785 In Tolerance: False
Point Record ID: 51 Time Stamp: 3/3/2017 9:39:54 AM
Name: WF2510
Code: EOC RECT 6/
Method: StaticObservation
Classication: Normal
Deleted: False
ECFDeltas-
DeltaX: -14179.040909261 In Tolerance: True
DeltaY: -3572.663623059 In Tolerance: True
DeltaZ: -8319.860760785 In Tolerance: False