I am working on this since the past 2 hours.I have an XML file which looks like this
<catalog>
<captureInfo>
<row>5</row>
<col>5</col>
</captureInfo>
<patientInfo>
<name>XYZ</name>
<detail>details here</detail>
</patientInfo>
<imageData>
<r0c0>
<contrastFlag>true</contrastFlag>
</r0c0>
<imageData>
<catalog>
I want to change the value of contrastFlag. I tried this but its not working
XDocument xdoc = XDocument.Load(filename)
xdoc.Element("catalog")
.Element("imageData")
.Descendants()
.Where(x => x.Value == "r0c0")
.First()
.SetElementValue("contrastFlag", "newValue");
doc.Save("XMLFile1.xml");
Can I know where I am going wrong and what would be the correct approach?
x.Name == "r0c0"<imageData>and<catalog>tags are not closed properly, but after that is fixed, this works for mexdoc.Element("catalog").Element("imageData").Element("r0c0").SetElementValue("contrastFlag", "newValue");