This is Guardian.re, which is a custom XML file that I've createed in C#. I have created a new program that I want to read this file and place the info in a listbox. The xmlns being the name of the user that was entered. How do I do this?
<?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" />
Here is the C# source:
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();
}
Use XPath to get your individual values back from the file as found here
http://support.microsoft.com/kb/308333
and then add the values to the listbox as specified here
http://msdn.microsoft.com/en-us/library/aa288403(v=vs.71).aspx
You can also find some code here Parse XML and populate in List Box
I posted a possible answer for this here: Reading an XML File With Linq
Guess I probably should have waited, as the other is in regards to Linq...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.