首页 > Windows开发 > 详细

linq to xml C#

时间:2018-12-12 12:49:38      阅读:157      评论:0      收藏:0      [点我收藏+]

private string GetResponseErrorMsg(string transactionid, Dictionary<string, string> errorMsg)
{
//key除了head 都是 CTO 加msg
string xmlpath = HttpContext.Current.Request.PhysicalApplicationPath + "//XML//Receive//" + transactionid + ".xml";

XDocument doc = XDocument.Load(xmlpath);
XElement rootLinq = doc.Root;


rootLinq.Name = "RESPONSE";
foreach (var item in errorMsg)
{
if (item.Key == "head")
{
XElement CTODhead = rootLinq.Element("HEADER");
if (CTODhead != null)
{

XElement errorMsgRoot = new XElement("MESSAGE", item.Value);

CTODhead.Add(errorMsgRoot);

}
}

XElement CTODelete = (from CTO in rootLinq.Element("BODY").Element("CTOS").Elements() where CTO.Element("NAME").Value == item.Key select CTO).SingleOrDefault();
if (CTODelete != null)
{
CTODelete.Element("CONFIGURATION").Remove();
XElement errorMsgRoot = new XElement("MESSAGE", item.Value);

CTODelete.Add(errorMsgRoot);

}


}

return doc.ToString();
}

linq to xml C#

原文:https://www.cnblogs.com/watchfluture/p/10107684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!