I'm relatively new to c#. Been given the job of remaking a public site our company hosts. The site will have many visitors, and some of it's content needs to be xml driven.
So far I've been able get diferent tests working, but there are so many methods I don't exactly see which one is best. Thats mainly my question. For a public xml driven site whats the best method for reading an xml file into the contents of the site. I've researched examples using xmldocument, xmltextreaders, datagrids ect.. So far I like the xmlTextReader method but I'm not to sure its the best method. Below is some sample code I'm using for one part of the site. I return the string to an aspx page.
Any help would be appreciated, thanks in advance.
So far I've been able get diferent tests working, but there are so many methods I don't exactly see which one is best. Thats mainly my question. For a public xml driven site whats the best method for reading an xml file into the contents of the site. I've researched examples using xmldocument, xmltextreaders, datagrids ect.. So far I like the xmlTextReader method but I'm not to sure its the best method. Below is some sample code I'm using for one part of the site. I return the string to an aspx page.
Code:
private string readXML() {
string message = "";
XmlTextReader xmlReader = null;
xmlReader = new XmlTextReader(Server.MapPath("careers.xml"));
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
while (xmlReader.Read())
{
switch (xmlReader.Name.ToString())
{
case "careers":
if (xmlReader.IsStartElement())
{
message +="<div id='mainContainer'>";
}
else {
message +="</div>";
}
break;
case "job":
if (xmlReader.IsStartElement())
{
xmlReader.MoveToAttribute(0);
message += "<span class='title'>" + xmlReader.Value + "</span><br />";
}
break;
case "description":
if (xmlReader.IsStartElement())
{
message += "<p class='jobDesc'>" + xmlReader.ReadString() + "</p>";
}
break;
case "list":
if (xmlReader.IsStartElement())
{
message += "<ul>";
xmlReader.MoveToAttribute(0);
message += xmlReader.Value;
}
else {
message += "</ul>";
}
break;
case "li":
if (xmlReader.IsStartElement())
{
message += "<li>" + xmlReader.ReadString() + "</li>";
}
break;
default:
break;
}
}
return message;
}