简体   繁体   English

如何在c#中的指定位置编写xml文档?

[英]How to write xml document in specified location in c#?

XmlDocument xmldoc = new XmlDocument();
XmlElement elem = xmldoc.CreateElement("Root");
elem.SetAttribute("NAME", "KARTHIK");
elem.SetAttribute("NO", "9859");
xmldoc.Save(@"D:\kk.xml");

i unable to save XML document in to this specified location.我无法将 XML 文档保存到此指定位置。 help me.帮我。

You never add the element you create to the document, call:您永远不会将您创建的元素添加到文档中,请调用:

xmldoc.AppendChild(elem);

Before .Save() as currently your attempt to save a document with no root will fail..Save()之前,目前您尝试保存没有 root 的文档将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM