c# - Convert string with XML to datatable, list or something more manageable? -


without having manually parse file, .net have convert string xml xmlelement, datatable, list or that's more manageable?

this actual string. string stored in xmlnode object (this xmlnode.outerxml), not know how convert can use:

<ni>     <nss>20150927</nss>     <gp>addon</gp>     <ns>counterblah1</ns>     <ns>counterblah2</ns>     <ns>countersales</ns>     <ns>counterblah4</ns>     <ns>counterblah5</ns>     <ns>counterblah6</ns>     <nv>         <nad>style=1,rfu=1,id=132</nad>         <r>0</r>         <r>15</r>         <r>8</r>         <r>3</r>         <r>2</r>         <r>2</r>     </nv>     <nv>         <nad>style=1,rfu=1,id=433</nad>         <r>0</r>         <r>15</r>         <r>30</r>         <r>3</r>         <r>2</r>         <r>2</r>     </nv>     <nv>         <nad>style=1,rfu=1,id=665</nad>         <r>0</r>         <r>15</r>         <r>90</r>         <r>3</r>         <r>2</r>         <r>2</r>     </nv> </ni> 

thanks.

using linq-to-xml can data this

//using system.xml.linq; //using system.linq;  //xmlstr = xml string var xdoc = xdocument.parse(xmlstr); var nvs = xdoc.descendants("nv"); var nads = nvs.select(nv => nv.elements("nad").first().value).tolist(); var thirdrs = nvs.select(nv => nv.elements("r").elementat(2).value).tolist(); 

this code generates, sample xml

nads = [ "style=1,rfu=1,id=132", "style=1,rfu=1,id=433", "style=1,rfu=1,id=665" ]
thirdrs = [ "8", "30", "90"]


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -