Sma*_*EGA 1 c# xml linq xelement
如何查看以下 C# 代码的 XML 输出?我可以看到它使用 XElement,但是我可以在哪里找到 XML 文件或输出?
private void Form1_Load(object sender, EventArgs e)
{
XElement doc = new XElement("searchresults"); // root element
//create
XElement result = new XElement("result",
new XElement("Resulthead", "AltaVista"),
new XElement("ResultURL", "www.altavista.com/"),
new XElement("Description", "AltaVista provides the most comprehensive search experience on the Web! ... "),
new XElement("DisplayURL", "www.altavista.com/")
);
doc.Add(result);
//add another search result
result = new XElement("result",
new XElement("Resulthead", "Dogpile Web Search"),
new XElement("ResultURL", "www.dogpile.com/"),
new XElement("Description", "All the best search engines piled into one. All the best search engines piled into one."),
new XElement("DisplayURL", "www.dogpile.com/")
);
doc.Add(result);
string xmlString = doc.ToString(SaveOptions.DisableFormatting);
}
Run Code Online (Sandbox Code Playgroud)
您的结果仅存在于您的“xmlString”变量中 - 它不会被写入任何地方,既不会写入控制台/窗口,也不会写入文件。
你必须添加一个
doc.Save(@"C:\your-xml-file-name.xml");
Run Code Online (Sandbox Code Playgroud)
方法末尾的行将内容保存到磁盘上的文件中。
确保使用完整路径,或检查应用程序运行所在的当前目录(即(yourappname)\bin\debug,最有可能是在 中)。
马克
| 归档时间: |
|
| 查看次数: |
4012 次 |
| 最近记录: |