我一直在试验 LINQ to XML,遇到了一个非常基本的问题。出于某种原因,将树转储到 System.Console 时我没有看到 XML 声明。
using System;
using System.Xml.Linq;
...
public static void Main(string[] args)
{
// Build tree.
XDocument xd = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
// Output tree.
System.Console.WriteLine(xd);
// Pause.
System.Console.ReadLine();
}
有人可以解释我做错了什么基本事情吗?
谢谢,
斯科特
最佳答案
向 XDoc 添加一些真实数据。并确保使用 Save() 方法查看全部内容:
XDocument xd = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xd.Add(new XElement("top"));
xd.Save(Console.Out);
关于c# - 在 System.Console 上查看 XML 声明时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2010327/