I have this code here:
static class Program
{
static void Main()
{
// get the xml as a string; note that we could also use
// Deserialize(Stream) to process a FileStream, but this
// works fine
string xml = File.ReadAllText(@"C:\Users\projects.xml");
var ser = new XmlSerializer(typeof(xmlRoot));
var root = (xmlRoot)ser.Deserialize(new StringReader(xml));
foreach (var properties in root.Properties)
{
Console.WriteLine("LABEL_D: " + properties.LABEL_D);
Console.WriteLine("LABEL_E: " + properties.LABEL_E);
}
}
}
[XmlRoot("SHEET")]
public class xmlRoot
{
private readonly List<Properties> properties = new List<Properties>();
[XmlArray("PROPPAGE"), XmlArrayItem("CONTROL")]
public List<Properties> Properties { get { return properties; } }
}
public class Properties
{
[XmlAttribute("LABEL_D")]
public string LABEL_D { get; set; }
[XmlAttribute("LABEL_E")]
public string LABEL_E { get; set; }
}
I have two xml files for which I want to retrieve the LABEL_D and LABEL_E attribute, so based on my code I want to be able to parse a string in the Main method and access the data.
I need to save the foreach loop in a list and at the end I need to return that list.
No comments:
Post a Comment