私は、指定されたパスからXMLファイルを読み込み、オブジェクトの配列にロードするSubを作成しています。なんらかの理由で、アルゴリズムは名前に対してうまく機能しますが、コストタグとタイプタグでは動作しません。何が起こっている?XML Reading Sub not working
(UPDATE:はを働くことを拒否し、それが空の文字列を返す、またはコストの場合には意味:0)ここで
は私のコードです:ここでは
Public Sub New(ByVal Path As String)
Try
Dim XML As New XmlTextReader(Path)
Try
Dim Bool As Boolean = False
Dim Name As String = ""
Dim Cost As Double = 0
Dim Type As String = ""
While True
XML.Read()
If Bool Then
Select Case XML.Name
Case Is = "name"
XML.Read()
Name = XML.Value
Case Is = "cost"
XML.Read()
Double.TryParse(XML.Value, Cost)
Case Is = "type"
XML.Read()
Type = XML.Value
End Select
End If
If XML.Name = "card" Then
Bool = True
End If
If Not CheckNulls(Name, Cost, Type) Then //CheckNulls returns true if all arguments passed to it are either empty strings, or 0
Dim Card As New Card(Name, Cost, Type)
Deck.Add(Card)
Cost = 0
Name = ""
Type = ""
Bool = False
End If
End While
Catch Ex As Exception
Exit Sub
End Try
Catch Ex As Exception
MsgBox("The System has encountered an error. Running the software anymore could cause a serious malfunction. Please exit now", MsgBoxStyle.OkOnly, "Error Message")
End Try
End Sub
はXMLですファイル: モナリザ芸術 の水玉 35.85 アートXMLデータを読み込み
あなたは「仕事を拒否した」とは何を意味するか:そこにエラーが発生するか、など、単に空の文字列であるのでしょうか?さらに、解析しようとしているXMLファイルを提供してください。 – DAXaholic
「XPath」式について知るあなたはもっと幸せになるでしょう。 http://www.w3schools.com/xsl/xpath_syntax.asp –
@Pradeep Kumar VB.NETでXPathを使用するにはどうすればよいですか? –