作者:加勒比海盗的骷髅_829 | 来源:互联网 | 2023-06-12 14:27
Imtryingtoputsub-childvaluesfromXMLintoadictionarycollectionusingLINQ.Ivedonethis
I'm trying to put sub-child values from XML into a dictionary collection using LINQ. I've done this with lists and custom collections which follow the same structure as the XML but am unable to search for specific values. If I know parentName, childName, and subChildName I want to be able to find subChildProperty1.value and subChildProperty2.value without iterating through the entire collection and each of the subsequent sub-collections, as I have to do with lists. This may not be the best implementation, and am open to suggestions, but still would like to figure out how to make this work. This would then allow me to have a dictionary item be:
我正在尝试使用LINQ将XML中的子子值放入字典集合中。我用列表和自定义集合完成了这些操作,这些集合遵循与XML相同的结构,但无法搜索特定值。如果我知道parentName,childName和subChildName,我希望能够找到subChildProperty1.value和subChildProperty2.value,而不必遍历整个集合和每个后续子集合,就像我必须处理列表一样。这可能不是最好的实现,我愿意接受建议,但仍想弄清楚如何使这项工作。这将允许我有一个字典项目:
key = "parentNameValue1.childNameValue1.subchildNameValue1.subChildProperty1"
value = 0
and I could just concatenate strings to form a specific key and search on that key to return a value.
我可以只连接字符串以形成一个特定的键,并搜索该键以返回一个值。
XML:
parentNameValue1
childNameValue1
subchildNameValue1
0
5
subchildNameValue2
0
10
This question is somewhat similar to " rel="nofollow noopener" target="_blank">this question here but I could not get the code working in VB for my application.
这个问题在这里有点类似于这个问题但是我无法在VB中为我的应用程序使用代码。
I am new to SO (and VB) so I apologize if my etiquette is incorrect.
我是SO(和VB)的新手,所以如果我的礼仪不正确,我会道歉。
1 个解决方案