xmlスキーマに一致するvb.netクラスがありますか?そうでない場合は、この投稿に沿ってhttps://stackoverflow.com/a/17315863/832052を生成することができます。
クラスは次のようになります。
'''<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
今、あなたはvb.netでクラスを持っていることを、あなたはクラスのインスタンスにXMLドキュメントをシリアライズとデシリアライズすることができます。
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
私はあなたがこれを持っていると仮定すると、PointRecord
の配列でモデルを生成するために別の<PointRecord ID="00000050" TimeStamp="2017-03-03T09:39:54">
ノードを追加しました。
<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>
テストするとき、私のXML文書には2つのPointRecords
がありました。プログラムの出力:
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
出典
2017-03-10 21:50:55
djv
xmlドキュメントは使用可能なノードの良い例ですか?あるいは、多かれ少なかれノードと子孫レベルが存在する可能性がありますか? – djv
ファイルには何百ものノードがありますが、特定の属性を持つノードのみを選択しています。しかし、これらのノードにはいくつかのレベルの子孫があるため、子孫のレベルは兄弟から兄弟に変化します。私は現在それに近づいているので、可能な限り多くのレベルまでドリルダウンするための「for-each」ループがネストされていますが、どれくらいのドリルをしてドリルを停止するのかを知ることは難しいです。言い換えれば、どのくらい入れ子にするか。あなたの興味に感謝します。私はこれを正しく説明してくれることを願う。 –
xmlを読むためにどの技術を使用しているのかよくわかりません。私は多くのXML文書を使用しますが、それらは常に標準モデルに従います。あなたが提供したモデルに基づいて回答を投稿します。それはあなたのために働くかもしれません(しかし、あなたの要件に基づいてより多くのモデルを生成する可能性があります)。私の答えを見てください。 – djv