以下代码应该从XML文件中读取并在控制台中显示结果:
class Program
{
static void Main(string[] args)
{
Program introToVCS = new Program();
System.Xml.Serialization.XmlSerializer reader = new
System.Xml.Serialization.XmlSerializer(introToVCS.GetType());
// Read the XML file.
System.IO.StreamReader file =
new System.IO.StreamReader("Customer.xml");
// Deserialize the content of the file into a Program object.
introToVCS = (Program)reader.Deserialize(file);
Console.WriteLine(introToVCS);
Console.ReadLine();
}
}
答案 0 :(得分:0)
这应该有效。使用文件名包括路径
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication7
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
Console.WriteLine(doc.ToString());
}
}
}