このサイトの他のおかげで、元の問題は修正されましたが、新しいものがありました。XML vbのネストされたデータ
パスを表示せずに、コンボボックスに入力するためにブランチの名前フィールドをプルできる必要があります。
が選択され、ボタンをクリックすると、選択したブランチのパスにあるすべてのファイルをUSBにコピーする必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<Versions>
<Version>
<Trunk>GapGun Software Version 7.1</Trunk>
<Branch Name=".142" Path="\\MEDIA-SERVER\Plex"/>
<Branch>.145</Branch>
<Branch>.148</Branch>
<Branch>.153</Branch>
<Branch>.176</Branch>
</Version>
<Version>
<Trunk>GapGun Software Version 7.2</Trunk>
<Branch>.152</Branch>
<Branch>.155</Branch>
<Branch>.158</Branch>
<Branch>.163</Branch>
<Branch>.166</Branch>
</Version>
</Versions>
Imports System.IO
Public Class Form1
Private Response As Object
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xelement As XElement = XElement.Load("F:\Test.xml")
Dim Versions As IEnumerable(Of XElement) = xelement.Elements()
For Each Version In Versions
Console.WriteLine(Version.Element("Trunk").Value)
ComboBox1.Items.Add(Version.Element("Trunk").Value)
Next Version
ComboBox3.Items.AddRange(System.IO.Directory.GetLogicalDrives)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Clear()
ComboBox2.Text = ""
Dim xelement As XElement = XElement.Load("F:\Test.xml")
Dim name =
From nm In xelement.Elements("Version")
Where CStr(nm.Element("Trunk")) = ComboBox1.Text
Select nm
For Each xEle As XElement In name
Dim branches = xEle.Elements("Branch").Select(Function(el) el.Value).ToArray()
Console.WriteLine(xEle)
ComboBox2.Items.AddRange(branches)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class
それは現時点で唯一のサンドボックスである必要がある場合も、私は何の問題再編のXMLを持っていません。
とは何ですか?何かエラーが出ていますか? – derloopkat
ブランチを取得するにはどうすればいいですか?パスを表示せずに.142をコンボボックスに入れ、次にボタンをクリックするとファイルをパスからusbにコピーします。このプログラムは、ソフトウェアのバージョンを選択し、インストールのためにファイルをUSBにコピーするために使用されますが、各ブランチは別の場所に保存されます。私はそれをより明確にするために質問を編集しました –
あなたからのコードを使用して前の投稿:https://stackoverflow.com/questions/46985365/reading-xml-data-using-linq-multiple-elements-with-the-same-名前-vb – jdweng