c# - Load xml row into 2D array -


so have xml

<document>   <month>     <depth>-0,25</depth>     <october>0,95</october>     <november>-0,90</november>     ...   </month>   <month>     <depth>-0,5</depth>     <october>0,47</october>     <november>-0,17</november>     ...   </month>   ... </document> 

i've searched bit , saw way linq 1d array, becasue end be

array[0,0] = -0.25 array[0,1] = 0.95 array[0,2] = -0.90 ... 

if you're happy jagged array (an array of arrays) linq makes easy:

xdocument doc = xdocument.load(...); var array = doc.root                .elements("month")                .select(month => month.elements().select(x => (double) x).toarray())                .toarray(); 

if need rectangular array, that's trickier.

personally build custom type depth, october , november properties, rather relying on order of elements within month, that's different matter.

note above cast double (probably?) fail values you've got there - more conventional xml use . instead of ,. however, if fail can use double.parse(x.value, someappropriateculture) instead.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -