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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -