Avatar of vcharles
vcharles asked on

Help with updating/adding data elements from fileB to fileA

Hello,

When I save my data I have file B, how do I look for same LinkAID in file A and replace its data elements with data elements in file B? and If LinkAID in file B is not in File A, How to I append its data elements in File A?


FileA:

<table>
<LinkAID>1<LinkAID>
<First>ItemA</First>
<Last>ItemB</Last>
<Date>Itemc</Date>
</table>
<table>
<LinkAID>2<LinkAID>
<First>ItemD</First>
<Last>ItemE</Last>
<Date>ItemF</Date>
</table>
<table>
<LinkAID>3<LinkAID>
<First>ItemG</First>
<Last>ItemH</Last>
<Date>ItemI</Date>
</table>


FileB:

<table>
<LinkAID>1<LinkAID>
<First>ItemA</First>
<Last>ItemB</Last>
<Date>temc</Date>
</table>
<table>
<LinkAID>2<LinkAID>
<First>ItemD</First>
<Last>ItemE</Last>
<Date>ItemF</Date>
</table>
<table>
<LinkAID>3<LinkAID>
<First>ItemG</First>
<Last>ItemH</Last>
<Date>temI</Date>
</table>
Visual Basic.NET.NET ProgrammingXML

Avatar of undefined
Last Comment
vcharles

8/22/2022 - Mon
Julian Hansen

How familiar are you with reading and writing XML documents?

You should just be able to query the one file for the LinkAID element and set its value based on the value you read from FileA - or append if not found.

Before writing any code - best to first understand the basics - so let us know what your level is and post any code you have attempted with this and lets take it from there.
ASKER
vcharles

Hi,

I know how to add data to an xml file but I need help with comparing values of an xml file with another xml file and then either add or replace values. Below is an example of saving data selected from a Grid to an xml file.

Dim MyDocLinkSSADB As XDocument = XDocument.Load(Application.StartupPath + "\LinkSSADB.xml")

            Dim LinkID = (From el In MyDocLinkSSADB.Descendants("LinkA") Select Int(el.<LinkAID>.Value)).ToList
            LinkID.Sort()
            Dim xNewLink As XElement = New XElement("LinkA")
            xNewLink.Add(New XElement("LinkAID", (LinkID.Last() + 1)))




            MyDocLinkSSADB.Root.Add(New XElement("LinkA", New XElement("LinkAID", (LinkID.Last() + 1)), New XElement("Order_ID", ComboBox1.SelectedIndex), New XElement("Problem_ID", SearchIdProblemeID), New XElement("POC_ID", POCid), New XElement("POC_ID", POC2id)))
            MyDocLinkSSADB.Save(Application.StartupPath + "\LinkSSADB.xml")

Thanks,


Victor
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
vcharles

Hi,

Thanks for the link, but I still can't figure the code to solve this issue, can you please send me an example.

Thanks,

Victor
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Julian Hansen

It will have to wait until next week - I am away until then - you can either request attention for a notification to be sent out to additional experts or hang on until next week.
ASKER
vcharles

OK, I will request attention for but would appreciate your help next week if this issue is not resolved. Thanks for your feedback.