首页 > 学院 > 开发设计 > 正文

Linqtoxml修改CDATA节点值

2019-11-14 13:37:08
字体:
来源:转载
供稿:网友

增加节点时,我们是这样写的:

xop.Document.Element("messages").Add(                        new XElement("message",                            new XAttribute("event", model.EventType),                            new XElement("subject", model.Subject),                            new XElement("body", new XCData(model.Body))));

更新节点,如果这样写就会报错: LINQ XObject 不能用作值。

element.SetElementValue("body", new XCData(model.Body));

改成ReplaceWith就OK了:

element.Element("body").ReplaceWith(new XElement("body", new XCData(model.Body)));

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表