Avatar of vcharles
vcharles
 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
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
vcharles

8/22/2022 - Mon
vcharles

ASKER
Help.
ASKER CERTIFIED SOLUTION
Robert Schutt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vcharles

ASKER
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
vcharles

ASKER
Thank You!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Robert Schutt

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?
vcharles

ASKER
I chose the second one, better incase dataelment already exist.

Thanks,

Victor