2011-10-24 40 views
0

我已經在C#中編寫了一個代碼來解析XML文件(Monodevelop)中的數據。我使用(使用System.Xml)和(命名空間)。它在(使用System.Xml)中給出錯誤名稱空間中不存在類型和名稱空間名稱「Xml」。我是編程新手。所以,請幫助我該怎麼做?當XML c#解析時卡住

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(); 
    } 
} 

}

+1

**向我們展示**代碼和一個示例XML! –

+0

如果你使用Monodevelop和編譯Mono,你不應該使用System.Xml,而是Mono等價的。 –

+0

什麼是Monodevelop的System.Xml等價物? –

回答

5

你有沒有加入到項目文件(文件夾引用)裝配的System.Xml參考?

+0

是的,我也在項目文件和調試文件夾中添加了System.Xml。 :S –

+0

我在Dektop中創建了該項目,並將該庫粘貼到項目和bin以及調試文件夾中。 –

+0

以下是我的代碼。我以有組織的形式複製它:D –