我正在尝试在c#
中编译一个简单的应用程序,该应用程序将从XML
文件中读取。这是我的代码和我遇到的错误的详细信息
ERROR1
errors :Error 1 The type or namespace name 'XmlReader' could not be
found (are you missing a using directive or an assembly reference?)
c:\users\javed15\documents\visual studio
2010\Projects\SalaryReader\SalaryReader\Program.cs 16 1 SalaryReader
误差2
2:Error The name 'XmlReader' does not exist in the current context
c:\users\javed15\documents\visual studio
2010\Projects\SalaryReader\SalaryReader\Program.cs 16 20 SalaryReader
误差3
Error 3 The name 'XmlNodeType' does not exist in the current context
c:\users\javed15\documents\visual studio
2010\Projects\SalaryReader\SalaryReader\Program.cs 21 25 SalaryReader
enter code here
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SalaryReader
{
class Program
{
static void Main(string[] args)
{
String XMLDataFilePath= @"C:\\XMLSalaries.xml";
String EmployeeName = "";
int varNoRecord = 0;
XmlReader Reader = XmlReader.Create(XMLDataFilePath);
Console.Write("Enter the Name of Person: ");
EmployeeName=Console.ReadLine();
while (Reader.Read()==true)
{
if ((Reader.NodeType == XmlNodeType.Element))
{
if (Reader.HasAttributes & Reader.GetAttribute("Name")==EmployeeName)
{
Console.WriteLine("Salary Of " + Reader.GetAttribute("Name") + " = " + Reader.GetAttribute("CurrentSalary"));
varNoRecord = 1;
}
}
}
if (varNoRecord == 0)
Console.WriteLine("Oop! No Person with the name "+EmployeeName+" was found");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}