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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -