c# - Namespace redefinition exception if XmlTextWriter is declared a certain way -
i bulding xdocument , serializing utf8 string following code:
string xmlstring = ""; using (memorystream ms = new memorystream()) { using (xmlwriter xw = new xmltextwriter(ms, encoding.utf8)) { doc.save(xw); xw.flush(); streamreader sr = new streamreader(ms); ms.seek(0, seekorigin.begin); xmlstring = sr.readtoend(); } }
this worked fine.
i needed toggle whether or not declarator serialized string. changed code this:
string xmlstring = ""; using (memorystream ms = new memorystream()) { xmlwritersettings settings = new xmlwritersettings() { omitxmldeclaration = !root.includedeclarator, encoding = encoding.utf8 }; using (xmlwriter xw = xmltextwriter.create(ms, settings)) { doc.save(xw); xw.flush(); streamreader sr = new streamreader(ms); ms.seek(0, seekorigin.begin); xmlstring = sr.readtoend(); } }
this throws following exception on doc.save(xw):
the prefix '' cannot redefined '' 'my_schema_here' within same start element tag.
i trying figure out why xdoc can saved if writer "new"ed up, not if ".create"d. ideas?
jordon
i fixed adding namespace name of root element in xdocument. still, it's strange isn't necessary if "new xmltextwriter()" used instead of "xmltextwriter.create()" or "xmlwriter.create()".
jordon
Comments
Post a Comment