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>
vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
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.
0
vcharlesAuthor Commented:
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
0
Julian HansenCommented:
but I need help with comparing values of an xml file with another xml file and then either add or replace values

XML documents are structured and can be queried - usually using something called XPath.

That means you can find the exact element you want and get its value - you would do this on both XML files to get the value you need - compare them and then either update the FileB using the same mechanism - or append to the file - again using the same mechanism.

Don't have time to put together a sample but try these links for now

http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C

http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

vcharlesAuthor Commented:
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
0
Julian HansenCommented:
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.
0
vcharlesAuthor Commented:
OK, I will request attention for but would appreciate your help next week if this issue is not resolved. Thanks for your feedback.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.