Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim strItemNumber As String
'set up the xml doc
Dim eConnect As XElement = _
<eConnect>
<SOPTransactionType>
<taSopLineIvcInsert_Items>
<taSopLineIvcInsert>
<ITEMNMBR>100</ITEMNMBR>
</taSopLineIvcInsert>
<taSopLineIvcInsert>
<ITEMNMBR>101</ITEMNMBR>
</taSopLineIvcInsert>
<taSopLineIvcInsert>
<ITEMNMBR>102</ITEMNMBR>
</taSopLineIvcInsert>
</taSopLineIvcInsert_Items>
</SOPTransactionType>
</eConnect>
'loop through the doc and empty target elements
For Each SOPTransactionType In eConnect.Elements("SOPTransactionType")
Dim taSopLineIvcInsert_Items As XElement = _
SOPTransactionType.Element("taSopLineIvcInsert_Items")
For Each taSopLineIvcInsert In _
taSopLineIvcInsert_Items.Elements("taSopLineIvcInsert")
strItemNumber = taSopLineIvcInsert.Element("ITEMNMBR")
'need to be able to evaluate the contents of the node
'and possibly delete it.
If strItemNumber = "100" Or strItemNumber = "101" Then
'Remove won't work, so we use RemoveAll to EMPTY the node
taSopLineIvcInsert.RemoveAll()
End If
Next
Next
'now we make a second pass, and query all the empty nodes,
Dim x As New Xml.XmlDocument
Dim query = _
From c In _
eConnect.<SOPTransactionType>.<taSopLineIvcInsert_Items>.<taSopLineIvcInsert> _
Where c.HasElements = False _
Select c
'and delete them
query.Remove()
x.LoadXml(eConnect.ToString)
Me.RichTextBox1.Text = eConnect.ToString
End Sub
End Class