Tuesday, 7 August 2012

Reading the XML File to the Array


Reading the XML File to the Array.

XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;

using (XmlReader reader = XmlReader.Create(Server.MapPath(".\\XML\\data.xml"),settings))
{
while (reader.Read())
{
// Only detect start elements.
if (reader.IsStartElement())
{
// Get element name and switch on it.
switch (reader.Name)
{
case "Software":

reader.MoveToFirstAttribute();
software[s] = reader.Value;
s++;
break;

case "Version":
reader.MoveToElement();
reader.Read();
version[v] =reader.ReadContentAsString();
v++;
break;

case "Download_code":
reader.MoveToElement();
reader.Read();
Download_code[d] = reader.ReadContentAsString();
d++;
break;

case "Email":
reader.MoveToElement();
reader.Read();
Email[em] = reader.ReadContentAsString();
em++;
break;

case "FileToUpload":
reader.MoveToElement();
reader.Read();
FileToUpload[f] = reader.ReadContentAsString();
f++;
break;
}
}
}
}

// cheking the values orders are correct
if ((s - ((s + v + d + f + em) / 5)) != 0)
// Label1.Text = "Not match in the index values :: s:" + s + "v:" + v + "d:" + d + "em:" + em;
Label1.Text = "Contact Administrator . Error code 10";

No comments:

Post a Comment