我的XML文件格式为:
"<TestFile fileext="C:\TestFiles\TestFile2.txt">
</TestFile>"
这里的根元素是“TestFile”。我的任务是创建一个这种形式的新XML,我正在使用的查询是:
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a medtata file of the file " + args[0]),
new XElement("TestFile",path));
但不是
"<TestFile fileext="C:\TestFiles\TestFile2.txt">
</TestFile>"
,输出
"<TestFile>C:\TestFiles\TestFile2.txt</TestFile>"
如何获得所需的输出?
答案 0 :(得分:0)
试试这个
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a medtata file of the file " + args[0]),
new XElement("TestFile",new XAttribute("filetext", path)));
如果你想在XElement
中添加下一个参数中添加一些值Exmaple
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a medtata file of the file " + args[0]),
new XElement("TestFile",new XAttribute("filetext", path), "something"));