c# - Can i deserialize xml directly into a List -
this question has answer here:
- is possible deserialize xml list<t>? 7 answers
this might silly noobish question, please bear me =)
in program receive piece of xml akin this:
<markers> <marker id="35" name="test1" address="anyway123" type="event"/> <marker id="370" name="test2" address="" type="event"/> <marker id="251" name="test3" address="somewhere 1337" type="com"/> </markers>
what want know if there's way have class, containing sort of this:
private int id; private string name; private string address; private string type; public int id { { return id; } set { id = value; } } public string name { { return name; } set { name = value; } } public string address { { return address; } set { address = value; } } public string type { { return type; } set { type = value; } }
lets call "eventclass" , go like:
could go this: list eventlist = "xmlstuff"
and if yes, xml stuff entail? xd
regards, -logan =)
you can use standard xmlserializer
if you're willing make few modifications class:
- xml case-sensitive should use lower-case names properties (
id
,name
, etc. - create containing class array of data class
- add attribute
[xmlroot("markers")]
containing class - add attribute
[xmlelement("marker")]
array property
something this:
[xmlroot("markers")] public class eventlist { [xmlelement("marker")] public list<eventclass> eventclasses {get; set;} } public class eventclass { public int id {get; set;} public string name {get; set;} public string address {get; set;} public string type {get; set;} }
Comments
Post a Comment