0

Quick question--I'm having trouble with the xml manipulation syntax in VB.net. My xml file is very simple. Here is an example:

<C_Clients>
    <client>208</client>
</C_Clients>

I have the ability to add a new "client" using a textbox and a button, however I need to be able to remove a specific element that is placed in the textbox as well.

1
  • there are several ways to achieve that. Post codes you have to add new "client". What did you use XDocument, XmlDocument, something else? Commented Mar 29, 2014 at 1:51

1 Answer 1

1

Working example:

Dim xml = <C_Clients>
            <client>208</client>
            <client>209</client>
          </C_Clients>
Dim doc As New Xml.XmlDocument
doc.LoadXml(xml.ToString)
Dim clientNodes = doc.SelectNodes("//client")
For Each elem As Xml.XmlElement In clientNodes
  If elem.InnerText = textbox1.Text Then
    elem.ParentNode.RemoveChild(elem)
    Exit For
  End If
Next
MessageBox.Show(doc.OuterXml)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.