c# - XDocument automatically indents files on parse and does not remove indent on save -
i seeking regarding file saving of xml file using xdocument (not xmldocument).
so have xml file not have indentation (in fact 1 line). when read xdocument using xdocument.parse (after reading , storing string using streamreader
), resulting xdocument indented.
alright, thought fine long if can save file without indentation. however, though have
xmlwritersettings writersettings = new xmlwritersettings(); writersettings.newlineonattributes = false; writersettings.newlinehandling = newlinehandling.none; writersettings.indent = false;
and pass in when create xmlwriter
using (var writer = xmlwriter.create(u.tofilesystempath(), settings)) { xd.save(writer); }
the resulting xml file still has indentation. when debugging on visual studio, noticed writer
class xmlwellformedwriter
. have result? appreciated.
thank you.
saveoptions available on save()
tostring()
.
string xmlstring = @"<top> <first>1</first> <second>dude</second> <third>now</third> </top>"; xdocument doc = xdocument.parse(xmlstring); doc.save(@"c:\temp\noindet.xml", saveoptions.disableformatting); // string noindent = doc.tostring(saveoptions.disableformatting);
output:
Comments
Post a Comment