c# - How convert xml string UTF8 to UTF16? -


i have string of xml(utf-8).i need store string in database(ms sql). encoding string must utf-16.

this code not work, utf16xml empty

xdocument xdoc = xdocument.parse(utf8xml); xdoc.declaration.encoding = "utf-16"; stringwriter writer = new stringwriter(); xmlwriter xml = xmlwriter.create(writer, new xmlwritersettings()              { encoding = writer.encoding, indent = true });  xdoc.writeto(xml);  string utf16xml = writer.tostring(); 

utf8xml - string contains serialize object(encoding utf8).

how convert xml string utf8 utf16?

this might you

memorystream ms = new memorystream();         xmlwritersettings xws = new xmlwritersettings();         xws.omitxmldeclaration = true;         xws.indent = true;         xdocument xdoc = xdocument.parse(utf8xml);         xdoc.declaration.encoding = "utf-16";         using (xmlwriter xw = xmlwriter.create(ms, xws))         {              xdoc.writeto(xw);         }         encoding ut8 = encoding.utf8;         encoding ut116 = encoding.unicode;         byte[] utf16xmlarray = encoding.convert(ut8, ut116, ms.toarray());         var utf16xml = encoding.unicode.getstring(utf16xmlarray); 

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? -