Link to home
Create AccountLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with tranfereing data to anoth xml file

Hello,

I used the code below to save ID values of an xml file based using  “Where (c.Element("LinkAID").Value = Link_ID). I now modifed the code to save IDs for all records in using “Where (c.Element("LinkAID").Value <> 0)” How do I add a loop to transfer all the records instaed of one record where ("LinkAID").Value = Link_ID?.

Dim MyLink As XDocument = XDocument.Load(Application.StartupPath + "\App_DataA\LinkSSADB.xml")
        Dim XT As XElement = XElement.Load(Application.StartupPath + "\App_Data\LinkSSADB.xml")
        Dim GetNodeForID = From c In XT.Elements("LinkA")
          Where (c.Element("LinkAID").Value <> “”)
                      Select New XElement("LinkA",
                                          New XElement("LinkAID", c.Element("LinkAID").Value),
                                          New XElement("CountryUser_ID", c.Element("CountryUser_ID").Value),
                                          New XElement("CountryOrigin_ID", c.Element("CountryUser_ID").Value),
                                          New XElement("NSN_ID", c.Element("NSN_ID").Value),
                                        New XElement("FTL_ID", c.Element("FTL_ID").Value))
        If (Not IsNothing(GetNodeForID)) And (GetNodeForID.Any()) Then
            MyLink.Element("Root").Add(GetNodeForID.First)
            MyLink.Save((Application.StartupPath + "\App_DataA\LinkSSADB.xml"))
        End If
ASKER CERTIFIED SOLUTION
Avatar of nost2
nost2

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Victor  Charles

ASKER

Thanks for the code, will try it and get back to you.
Hi,

It worked. One more small issue. How do I clear the xml file before I insert new data in it?

Thanks,

Victor
Thank You!