2013-11-26 90 views
0

這是Guardian.re,它是我在C#中創建的自定義XML文件。我創建了一個新程序,我想要讀取此文件並將信息放入列表框中。 xmlns是輸入的用戶的名稱。我該怎麼做呢?閱讀自定義XML文件

<?xml version="1.0" encoding="utf-8"?> 
<!--This is the Guardian Submit file. An admin will read with their viewers.--> 
<Guardian 
    Age="5" 
    Hours="5" 
    Why="Why?" 
    Qualify="What qualifies you?" 
    xmlns="Name" /> 

這裏是C#源:

if (System.IO.File.Exists("Guardian.re") == false) 
      { 
       //.re is the file extension that is used 

       XmlWriter writer = XmlWriter.Create(@"Guardian.re"); 

       writer.WriteStartDocument(); 

       writer.WriteComment("This is the Guardian Submit file. An admin will read with their viewers."); 
       //Element <Guardian> in the .re XML format 
       writer.WriteStartElement("Guardian", IGN); 



       //the element <Age> in the .re XML format 
       writer.WriteAttributeString("Age", Age); 

       //the element <Hours> in the .re XML format 
       writer.WriteAttributeString("Hours", hours); 

       //the element <Why> in the .re XML format 
       writer.WriteAttributeString("Why", WhyRank); 

       //the element <Qualify> in the .re XML format 
       writer.WriteAttributeString("Qualify", Qualify); 
       writer.WriteEndElement(); 



       writer.Flush(); 
       writer.Close(); 
} 
+0

列表項的值和鍵是什麼? – Sico

+0

姓名:年齡:工作時間:爲什麼:資格要求:(每一個都是列表框中的新項目) – user2678408

+0

如果您使用[LINQ to XML](http://msdn.microsoft.com/zh-cn/vstudio/bb688087 .aspx)會更容易! –

回答