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 
 ; 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.
or
you can use loadxml
method , loop each node like
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.
Comments
Post a Comment