How would I parse my own XML..?



I made this XML file that I need to try and generate a GUI from. No I am not going to jump over to WPF if you were wondering :-)


Here is the XML that I made:



<?xml version="1.0" encoding="UTF-8"?>
<root>
<gui groupboxlabel="Barnets Stamdata" type="CHILD">
<textbox label="CPR" />
<textbox label="Navn" />
<textbox label="Efternavn" />
<textbox label="Addresse" />
<textbox label="Hus nr." />
<textbox label="Opgang" />
<textbox label="Post Nr." />
<textbox label="By" />
<textbox label="Email" />
<textbox label="Telefon nr." />
<textbox label="Sagsbehandler" />
<textbox label="Konsulent" />
<textbox label="Aflastning" />
<!-- <combobox label="Foranstaltning" /> -->
<!-- <date label="Anbring" /> -->
<!-- <date label="Udskriv" /> -->
</gui>
</root>


I need to find the gui tag first, so I can extract the 2 pieces of information there. Then I have to make a custom textbox control with a certain label name for every textbox child there.


I tried to do something like this at firs to try and print out what it looked like, but the code doesn't work because the child nodes that I find are null:



public void CreateNewLayout(Form parent, String path, String token)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);

XmlNodeList gui = xmlDoc.GetElementsByTagName("gui");
if (gui.Count == 0)
{
MessageBox.Show("XML fil har ingen elementer", "Fejl");
return;
}
while (gui.GetEnumerator().MoveNext())
{
gui.GetEnumerator().Current.ToString();
}
}


Problem is, my XML is pretty rusty...any help?


No comments:

Post a Comment