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

asked on

Help with checking for existing data element

Hi,

How do you check if data element exist before including in xml file to avoid duplicate data elements?  

 Dim xdoc As XDocument = XDocument.Load(Application.StartupPath + "\FILE1.xml")
        Dim results = (From n In xdoc.Root.Descendants("AOP6B")
                       Select n).ToList()
        results.ForEach(Sub(n) n.Add(<CA></CA>))
        xdoc.Save(Application.StartupPath + "\FILE1.xml")
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi Victor;

Please supply a true representation of the XML file.
When you say,, "checking for existing data element", is this within one parent node or in all nodes?
Does this mean that you want to insert the an empty <CA></CA> node in the document?
Where in the document do you want to insert the node?
Avatar of Victor  Charles

ASKER

Hi Fernando,

Below is an example of the xml file. I would like to add <CA></CA> at the end of the table if it does not already exist.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <Table1>
    <SN>9089</SN>
    <AGD>BHJK</AGD>
    <CHPT>104</CHPT>
    <RIC>YUXRT</RIC>
  </Table1>
</Root>

Thanks,

victor
So the document will only have one Table1 node in it? correct?
Yes, one table (Table1) with multiple records.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America 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
Thank You.
Not a problem Victor, glad to help.