【发布时间】:2013-11-26 15:38:11
【问题描述】:
这是 Guardian.re,它是我用 C# 创建的自定义 XML 文件。我创建了一个新程序,我想读取这个文件并将信息放在一个列表框中。 xmlns 是输入的用户名。我该怎么做?
<?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();
}
【问题讨论】:
-
列表项的值和键是什么?
-
姓名:年龄:小时:原因:资格:(每一项都是列表框中的新项目)
-
如果你使用LINQ to XML会容易得多!!