c# - Remove encoding from XmlWriter -
i'm using xmlwriter , xmlwritersettings write xml file disk. however, scheme parsing xml file complaining encoding.
<?xml version="1.0" encoding="utf-8"?> what wants this:
<?xml version="1.0" ?> if seek omitxmldeclaration = true, don't xml line @ all.
string destinationname = "c:\\temp\\file.xml"; string strclassification = "none"; xmlwritersettings settings = new xmlwritersettings(); settings.indent = true; using (xmlwriter author = xmlwriter.create(destinationname, settings)) { writer.writestartdocument(); writer.writestartelement("chunkdata"); writer.writeelementstring("classification", strclassification); writer.writeendelement(); }
just ran ---
removexmlwritersettings() altogether , utilize xmltextwriter()'s formatting field indention. pass in null encoding argument of xmltextwriter's ctor the next code create output you're looking for: <?xml version="1.0" ?>
var w = new xmltextwriter(filename, null); w.formatting = formatting.indented; w.writestartdocument(); w.writestartelement("chunkdata"); w.writeenddocument(); w.close(); the .close() creates file - using , create() approach work.
c# xml
No comments:
Post a Comment