LinqToXml;查询属性不存在的位置

时间:2011-10-12 13:04:20

标签: vb.net linq-to-xml

是否存在属性不存在的语法?

    Dim xe As XElement = _
    <xml>
        <el att1="ABC" att2="XYZ"/>
        <el att1="ABC"/>
        <el/>
    </xml>

    Dim xe2 As IEnumerable(Of XElement)
    xe2 = From c In xe.<el> Where c.@att1 = "ABC" And DoesNotExist(c.@att2)

    'Return: <el att1="ABC"/>

2 个答案:

答案 0 :(得分:1)

xe2 = From c In xe.<el> Where c.@att1 = "ABC" And c.@att2 Is Nothing

答案 1 :(得分:1)

试试String.IsNullOrEmpty(c.@att2)