Sample XML File
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<DoctorInfo>
<Doctor>
<id>01</id>
<name>Ranil Jayaweera</name>
<speciality>GI</speciality>
</Doctor>
<Doctor>
<id>02</id>
<name>Aruna Gunathilaka</name>
<speciality>VP</speciality>
</Doctor>
<Doctor>
<id>03</id>
<name>Jaya Palipana</name>
<speciality>VOG</speciality>
</Doctor>
</DoctorInfo>
[/sourcecode]
The Code
[sourcecode language="csharp"]
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Application.StartupPath + "\\DoctorsList.xml");
XmlNode rootNode = xmlDoc.SelectSingleNode("//DoctorInfo");
XmlNodeList doctorList = rootNode.SelectNodes("Doctor");
for (int i = 0; i < doctorList.Count; i++)
{
if (doctorList[i].SelectSingleNode("id").InnerText.Equals(“03”))
{
rootNode.RemoveChild(doctorList[i]);
xmlDoc.Save(Application.StartupPath + "\\DoctorsList.xml");
}
}
[/sourcecode]
No comments:
Post a Comment