converting xml to a datatable from a string c#? -


i trying xml string attachment using imapx later saves data byte[]. , after conversion, string has linebreaks represented \r\n.

byte[] att = w.filedata; str = system.text.encoding.default.getstring(att); 

the string seems have "\r\n" breaks instead of whitespace , new lines

str = str.replace("\r\n", " "); 

when try read xml using string reader read xml

stringreader sr = new stringreader("your xml"); dataset ds = new dataset(); ds.readxml(sr); 

it doesn't seem program can understand code in such format. have tried apply linebreaks in xml instead of \r\n using &#xa ; instead without success. xml works fine , converts datatable if retrieved file on system want able create datatable string directly

original xml:

<?xml version="1.0" standalone="yes"?> 

     <data>            <id>931304</id>            <age>26</age>       </data>      <data>            <id>932160</id>            <age>26</age>      </data>  <data /> 

it becomes on reading byte[] att string

<?xml version="1.0" standalone="yes"?> \r\n <documentelement> \r\n  <data>     \r\n <id>931304</id>  \r\n  <age>26</age>   \r\n      </data> \r\n   <data> \r\n               <id>932160</id>     \r\n          <age>26</age>     \r\n    </data> \r\n     <data /> \r\n </documentelement> 

the ds.readxml(sr);

does not recognize \r\n, , if replaced blank space.

you can not transfer xml datatable, xml wrong convert.

<?xml version="1.0" standalone="yes"?> <-- why "?" @ start , end. ...<data /> @ end 

either remove first line , last line, valid xml , convert datatable

or

you can use linq typeof data.

loading xml string datatable

or

you can use loadxml method , loop each node like

finding header value in xml

how display datatable xml writexml in nicely readable format?

updated or can use schema this.

first create schema - (how convert complex xml .net class?)

then parse xml schema , convert datatable.

how convert xml datatable in c#


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -