I am trying to generate class by which I can generate a HTML code from an XML file. It does generate the HTML code but when I have more than one tag in my XML file its value is reset.
I hope you could help me.
Here is my code in C#:
public class GenerateHTMLClass
{
public string htmlstringbegin = "<HTML><HEADER><title>My Web-page</title></HEADER><BODY><form>\r\n";
public string htmlstringend = "</form></BODY></HTML>";
public string htmlstring = "";
public GenerateHTMLClass(string xmlfileaddress, string htmlfilenaddress)
{
string id = "";
string name = "";
string type = "";
string value = "";
string htmlstring = "";
XmlTextReader reader = new XmlTextReader(xmlfileaddress);
while (reader.Read())
{
switch (reader.Name)
{
case "GUID":
id = reader.ReadString();
break;
case "Title":
name = reader.ReadString();
break;
case "Type":
type = reader.ReadString();
break;
}
}
htmlstring += "<" + type + " id=" + id + " value=" + name + "/>" + name + "</" + type + ">";
using (FileStream fs = new FileStream(htmlfilenaddress, FileMode.Create))
{
using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
{
writer.Write(htmlstringbegin + htmlstring + htmlstringend);
}
}
}
}
My xml file:
<Groups>
<Group1>
<Item1>
<Type>Button</Type>
<GUID>124342345</GUID>
<Title>Name</Title>
</Item1>
</Group1>
<Group2>
<Item2>
<Type>textarea</Type>
<GUID>1243dsfs42345</GUID>
<Title>Name</Title>
</Item2>
</Group2>
</Groups>