0

私の 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>"

どうすれば目的の出力を得ることができますか?

4

1 に答える 1

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 に次の引数を追加します

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"));
于 2013-10-06T15:27:25.427 に答える