c# - Formatting XML with tabulation and removing element ending space? -
i trying 2 things:
get output xml formated tabulation instead of spaces.
remove ending space generates video element.
" />
to
"/>
i have tried use
xmlwriter.formatting = formatting.indented;
as as
indentchar
but did not worked me dont know why.
this code have currently, hear advices , suggestion improve it:
xmldocument xmldoc = new xmldocument(); xmltextwriter xmlwriter = new xmltextwriter(filename, system.text.encoding.utf8); xmlwriter.writeprocessinginstruction("xml", "version='1.0' encoding='utf-8' standalone='yes'"); xmlwriter.writecomment(@" file made @author"); xmlwriter.writestartelement("videos"); xmlwriter.close(); xmldoc.load(filename); xmlnode root = xmldoc.documentelement; foreach (int myid in exportlistids) { xmlelement video = xmldoc.createelement("video"); root.appendchild(video); video.setattribute("videoid", myid.tostring()); } xmldoc.save(filename);
i have managed solve question 1 below code still don't know if possible remove space between "
, />
@ end of element vide question 2.
xmlwritersettings settings = new xmlwritersettings(); settings.encoding = encoding.utf8; settings.indent = true; settings.indentchars = "\t"; xmlwriter writexml = xmlwriter.create("test.xml", settings); writexml.writestartdocument(); writexml.writecomment(@" file made @author"); writexml.writestartelement("videos"); foreach (var item in mylist) { writexml.writestartelement("video"); writexml.writeattributestring("id", item.key.tostring()); writexml.writeattributestring("name", item.value); writexml.writestartelement("object"); writexml.writeattributestring("a", item.key.tostring()); writexml.writeattributestring("b", item.value); writexml.writeendelement(); writexml.writeendelement(); } writexml.writeendelement(); writexml.writeenddocument(); writexml.close();
Comments
Post a Comment