Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with adding data elements in string variable using VB.NET

Hi,

 How do you modify the code below to add data elements from a string variable (i.e. S = Effect, NSC, NSN, AGD)?

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
         Dim xdoc As XDocument = XDocument.Load(Application.StartupPath + "\AOP5.xml")
         Dim results = (From n In xdoc.Root.Descendants("AOP5")
                        Select n).ToList()
         Dim resultsa = (From n In xdoc.Root.Descendants("Effect")
                     Select n).Count()

         If resultsa = 0 Then
         results.ForEach(Sub(n) n.Add(<Effect></Effect>))
         End If

         xdoc.Save(Application.StartupPath + "\AOP5.xml")

Open in new window


 Thanks,

Victor
Avatar of Victor  Charles
Victor Charles
Flag of United States of America image

ASKER

Help.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

It worked. Thank You.

How do you modify the code to remove all Data elements in File1 not found in a string variable  S = "Effect, NSC, NSN, AGD"?

Victor
Thank You!
How do you modify the code to remove all Data elements in File1 ...
Which one did you choose?

Can you give an example input file?

EDIT: and output file?
I chose the second one, better incase dataelment already exist.

Thanks,

Victor