c# - To move XML node valus to my custom model -
i have string variable xml structure:
string str = "<people><person><firstname>daniel</firstname><lastname>wylie</lastname></person>"; it has 1 node only. need convert new model. converted xml firstly this:
xmldocument xmldoc = new xmldocument(); xmldoc.loadxml(xmlquery); now need move firstname , lastname values xml following model:
public class person { public string firstname { get; set; } public string lastname { get; set; } } how can this?
use xmlserializer
but because xml contain tag. create class people deserialization
public class people { public list<person> persons; } then try:
xmlserializer serial = new xmlserializer(people.gettype()); //convert yuor string textreader using (textreader reader = new stringreader(yourstring)) { people mans = serial.deserialize(reader); person man; if(mans.count > 0) man = mans[0]; }
Comments
Post a Comment