好的,我已经在这上面绞尽脑汁而无法让它发挥作用,所以任何帮助都会受到赞赏。当以下查询运行时,它将返回第一个" AccessItem"只要name属性匹配。如果我将相同的accessitem移动到第二个AccessItem,则不返回任何内容。显然,我只希望返回名称为Attribute的" AccessItem"(s)。
<payload>
<Product>
<Configuration>
<InternetTimeSettings>
<Enabled>False</Enabled>
<NISTServers>time-c.nist.gov,nist.time.nosc.us,wwv.nist.gov</NISTServers>
<GMTOffset>-5</GMTOffset>
<ObserveDaylightSaving>True</ObserveDaylightSaving>
</InternetTimeSettings>
<LogEntryTimeStamps>
</LogEntryTimeStamps>
<EventTimeStamps>
</EventTimeStamps>
</Configuration>
<UserAccess>
<AccessItem name="Administration" users="Admin" personas="Administrators" groups=""/>
<AccessItem name="Add Reports" users="Admin" personas="Administrators" groups=""/>
<AccessItem name="Edit Reports" users="Admin" personas="Administrators" groups=""/>
<AccessItem name="Delete Reports" users="Admin" personas="Administrators" groups=""/>
</UserAccess>
</Product>
</payload>
Dim xEL As XElement
xEL = XElement.Parse(//RefToAboveXML\\)
Dim TS As New UserAccessProperty
Dim TS As String = AccessItemName
Dim Query = From el In xEL.Elements("Product").Elements("UserAccess") Where el.Element("AccessItem").Attribute("name") = AccessItemName Select el
If Query.Count > 0 Then
For Each elm As XElement In Query
cUserAccess = elm
TS.Users = elm.Element("AccessItem").Attribute("users").Value
TS.Personas = elm.Element("AccessItem").Attribute("personas").Value
TS.Groups = elm.Element("AccessItem").Attribute("groups").Value
Next
End If
答案 0 :(得分:0)
更改您的LINQ以选择<AccessItem>
而不是<UserAccess>
:
Dim Query = From el In xEL.Elements("Product").
Elements("UserAccess").
Elements("AccessItem") '<- select <AccessItem>'
Where el.Attribute("name") = AccessItemName '<- filter only those with specific name attribute value'
Select el
If Query.Count > 0 Then
For Each elm As XElement In Query
TS.Users = elm.Attribute("users").Value
TS.Personas = elm.Attribute("personas").Value
TS.Groups = elm.Attribute("groups").Value
Next
End If