我正在尝试根据复选框的选择构建一个 XDocument 查询。
我有以下代码,它不起作用,因为我不确定所需的语法。我认为它试图实现的目标相当明显。这几乎是我之前在 SQL 中构建 Where 语句的方式。最终代码中将有大约 16 个复选框,这就是使用多个 If 语句的原因。
Private Sub NextWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextWord.Click
Dim WordDictionary As XDocument = XDocument.Load("Dictionary Resources\Dictionary.xml")
Dim CheckSelection As String
If NounCheckbox.Checked = True Then
CheckSelection = CheckSelection & "noun"
End If
If AdjectiveCheckbox.Checked = True Then
CheckSelection = CheckSelection & "adjective"
End If
Dim ToList = From x In WordDictionary.Root.Elements("Word") Where x.Elements("Type").Value = CheckSelection
For Each result In ToList
Console.WriteLine(result)
Next
End Sub
为了完整起见,XML 文件具有以下结构:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Word ID="1">
<Type>adjective</Type>
<English></English>
<Thai></Thai>
<Meaning></Meaning>
<Audio>Dictionary Resources\Sound Files\1.wav</Audio>
<Picture></Picture>
<Transliteration></Transliteration>
</Word>
...
...
</Root>