C# .NET - Before inserting new element in xml check if exists.

Asked By Rahul Khanna on 20-Jul-14 01:58 PM
Hi,

I have below a xml file with the below format:

<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Countries>
    <country>India</country>
    <country>USA</country>  
    <country>UK</country>      
</Countries>
</Root>

string newCountry="UAE"

I want to insert this "UAE" country to the above xml file, before that I want to check whether "UAE" is already exists in the xml. If not exists then only want to insert otherwise no operation. How can I do this?

xpath query examples - Robbe Morris replied to Rahul Khanna on 20-Jul-14 06:40 PM

http://www.nullskull.com/a/1625/xpath-examples-for-node-attribute-and-substring-queries.aspx