LINQ to XML 只拾取子元素而不是较低的同名元素

LINQ to XML just pickup child elements not lower same named elements

我正在使用 VB.net 轴符号来走一些返回的 XML。

XML 有我需要的 "type" 个节点列表。

它在 XML 中还有一些我目前不感兴趣的其他 "type" 节点。

我的代码:

 Dim locTypeList = ""

                For Each locationType In returnedXMLGoogle...<result>...<type>
                    locTypeList = locTypeList & locationType.Value & ","
                Next

                If locTypeList.Length > 0 Then locTypeList = Left(locTypeList, Len(locTypeList) - 1)

                'gpr.googlePlacesTypes = returnedXMLGoogle...<type>.Value

                 gpr.googlePlacesTypes = locTypeList

不幸的是,它会拾取数据结构中的每个子节点,甚至更远的子节点。

如何将循环限制为 <result> 节点下的那些节点?

使用子标签而不是后代标签:

returnedXMLGoogle...<result>.<type>

而不是

returnedXMLGoogle...<result>...<type>

这将只为您提供那些直接锚定到结果节点的类型节点。