Victor Charles
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 .StartupPa th + "\FILE1.xml")
Dim results = (From n In xdoc.Root.Descendants("AOP 6B")
Select n).ToList()
results.ForEach(Sub(n) n.Add(<CA></CA>))
xdoc.Save(Application.Star tupPath + "\FILE1.xml")
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
Dim results = (From n In xdoc.Root.Descendants("AOP
Select n).ToList()
results.ForEach(Sub(n) n.Add(<CA></CA>))
xdoc.Save(Application.Star
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
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?
ASKER
Yes, one table (Table1) with multiple records.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You.
Not a problem Victor, glad to help.
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?