code_junkie

Linq to XML 'Where not in' syntax problem

Nov 11th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Dim BasicGroups As String() = New String() {"Node1", "Node2"}
  2. Dim NodesToRemove = From Element In SchemaDoc.Root.<Group> _
  3. Where Element.@Name not in BasicGroups
  4. For Each XNode In NodesToRemove
  5. XNode.Remove()
  6. Next
  7.  
  8. where (not (list.Contains(foo))
  9.  
  10. Dim SchemaDoc As New XDocument(<Root><Group Name="Foo"/><Group Name="Node1"/>
  11. <Group Name="Node2"/><Group name="Bar"/></Root>)
  12. Dim NodesToRemove = From Element In SchemaDoc.<Root>.<Group> Where _
  13. Element.@Name Like "NotNode?"
  14. For Each XNode In NodesToRemove.ToArray()
  15. XNode.Remove()
  16. Next
  17.  
  18. Dim NodesToRemove As New Collections.ObjectModel.Collection(Of XNode)
  19. For Each Element In SchemaDoc.<Root>.<Group>
  20. If Not BasicGroups.Contains(Element.@Name) Then
  21. NodesToRemove.Add(Element)
  22. End If
  23. Next
  24.  
  25. Dim NodesToRemove = From Element In SchemaDoc.Root.<Group> _
  26. Where Not BasicGroups.Contains(Element.@Name)
Add Comment
Please, Sign In to add comment