S
Sudip_inn
Guest
This way i update data in xml file
XDocument xmlDoc = XDocument.Load(strPath);
var items = (from item in xmlDoc.Descendants("clsCommentPopup")
where item.Element("Section").Value.Trim().ToUpper() == section.Trim().ToUpper()
&& item.Element("LineItem").Value.Trim().ToUpper() == li.Trim().ToUpper()
select item).ToList();
bool IsFieldUpdated = false;
foreach (var item in items)
{
if (ignorecelldata != "")
{
if (_IsIgnored)
item.Element("IgnoreData").SetValue(ignorecelldata);
else
item.Element("IgnoreData").SetValue(string.Empty);
IsFieldUpdated = true;
}
}
if (IsFieldUpdated)
xmlDoc.Save(strCommentPath);
now i have to also search for ID element in each row by section and lineitem. if match found then i have to search ID element. if not found then i need to insert ID element in matched row where i will set a value for ID.
how to achieve it with XDocument. if possible discuss with a example code. thanks
Continue reading...
XDocument xmlDoc = XDocument.Load(strPath);
var items = (from item in xmlDoc.Descendants("clsCommentPopup")
where item.Element("Section").Value.Trim().ToUpper() == section.Trim().ToUpper()
&& item.Element("LineItem").Value.Trim().ToUpper() == li.Trim().ToUpper()
select item).ToList();
bool IsFieldUpdated = false;
foreach (var item in items)
{
if (ignorecelldata != "")
{
if (_IsIgnored)
item.Element("IgnoreData").SetValue(ignorecelldata);
else
item.Element("IgnoreData").SetValue(string.Empty);
IsFieldUpdated = true;
}
}
if (IsFieldUpdated)
xmlDoc.Save(strCommentPath);
now i have to also search for ID element in each row by section and lineitem. if match found then i have to search ID element. if not found then i need to insert ID element in matched row where i will set a value for ID.
how to achieve it with XDocument. if possible discuss with a example code. thanks
Continue reading...