我可以通过在XML中传递类似于SQL的查询(例如LIKE,CONTAIN,SUM等)来根据条件选择节点吗?
这是我的数据结构
<institutions>
<institution type="university" abbrv="absu" name="Abia State University (absu)" />
<institution type="university" abbrv="atbu" name="Abubakar Tafawa Balewa University (atbu)" />
<institution type="university" abbrv="achievers" name="Achievers University (achievers)" />
<institutions>
我希望能够使用LIKE和其他关键字获得机构。我可以获得xml的以下语句的等价物吗?
SELECT Institution FROM tblInstitutions WHERE Name LIKE&#39;%Abia%&#39;
答案 0 :(得分:0)
使用XML作为数据库
使用System.Xml.Linq
命名空间功能
Dim data As XElement =
<institutions>
<institution type="university" abbrv="absu" name="Abia State University (absu)"/>
<institution type="university" abbrv="atbu" name="Abubakar Tafawa Balewa University (atbu)"/>
<institution type="university" abbrv="achievers" name="Achievers University (achievers)"/>
</institutions>
'Search entries where `name` contains "Abia"
Dim result As IEnumerable(Of XElement) =
From institution As XElement In data.<institution>
Where institution.@name.Contains("Abia")
Select institution
使用其他LINQ方法Sum
,Avg
等LINQ to XML
还要检查vb.net XML Literals Overview (Visual Basic)