c# - XmlWriter.WriteStartDocument() is not outputting the declaration to the file -
ok have method should read xml documents , wrap them in bigger xml document.
<elements> <element> <element> </elements>
the issue when using code below output file missing declaration
<?xml >
any reason why is? hoping stupid missing.
xmlwriter xmlwriter = xmlwriter.create(outputfilename, xwssettings); xmlwriter.writestartdocument(); xmlwriter.writestartelement("elements"); foreach (var item in items) { xmlreader = xmlreader.create(item.fullfilename); while (xmlreader.read()) { if(xmlreader.nodetype == xmlnodetype.element) { xmlwriter.writeraw(xmlreader.readouterxml()); break; } } } xmlwriter.writeendelement(); xmlwriter.writeenddocument(); xmlwriter.flush(); xmlwriter.close(); xmlwriter = null;
as @tim had hightlighted check had xmlwritersettings incorrectly set
xmlwritersettings xwssettings = new xmlwritersettings(); xwssettings.checkcharacters = false; xwssettings.closeoutput = true; xwssettings.conformancelevel = conformancelevel.document; xwssettings.encoding = encoding.utf8; xwssettings.indent = false; xwssettings.newlinehandling = newlinehandling.none; xwssettings.omitxmldeclaration = true; <---- should have been false;
Comments
Post a Comment