c#中插入XML的命名空间
电脑版发表于:2019/7/11 21:04
直接贴代码吧
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));
XNamespace ns = "https://www.tnblog.net";
XElement root = new XElement(ns + "svg");
root.Add(
new XAttribute("xmlns", "https://www.tnblog.net"),
new XElement(ns + "bookname", "我记得有一个人"),
new XElement(ns + "bookdesc", "永远留在我心中")
);
document.Add(root);
string uri = Server.MapPath("~/xml/MyTest.xml");
document.Save(uri);效果如下:

