XML c# 解析时卡住了
我用 C# 编写了一段代码来解析 XML 文件中的数据 (Monodevelop)。我使用了(使用System.Xml)和(命名空间)。它给出了一个错误(使用System.Xml)命名空间中不存在类型和命名空间名称“Xml”。我是编程新手。那么,请帮帮我,我该怎么办?
using System;
using System.Xml;
namespace ReadXMLfromFile
{
class sample
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("sample.xml ");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each
element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the
element.
Console.Write ("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
}
I have written a code in C# to parse the data from an XML file (Monodevelop). I used (using System.Xml) and (namespace).It gives an error in the (using System.Xml) The type and namespace name "Xml" does not exist in the namespace. I am new to programming. So , Kindly help me what should I do ?
using System;
using System.Xml;
namespace ReadXMLfromFile
{
class sample
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("sample.xml ");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each
element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the
element.
Console.Write ("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在项目文件(文件夹引用)中添加了对程序集 System.Xml 的引用?
Have you added a reference to the assembly System.Xml in the project file (Folder References)?