c# - Writing file paths into XML file with XmlWriter -
c# - Writing file paths into XML file with XmlWriter -
i'm hoping can help me annoying little problem i'm having. i'm trying write file path xml settings file, nil happens. don't error messages or in time debugging windows, doesn't execute code block.
the programme feature 1 setup user accounts, , select file each account. if leave file paths blank, xml file created no problems. however, if there 1 path written file never gets created.
here sample of function:
private void savesettings() { xmlwritersettings xml_settings = new xmlwritersettings(); xml_settings.indent = true; xml_settings.indentchars = (" "); using (xmlwriter xml_settings_file = xmlwriter.create("settings.xml", xml_settings)) { xml_settings_file.writestartelement("main_node"); xml_settings_file.writeelementstring("settinga", properties.settings.default.settinga.tostring()); xml_settings_file.writeelementstring("settingb", properties.settings.default.settingb.tostring()); xml_settings_file.writeelementstring("settingc", properties.settings.default.settingc.tostring()); (int = 1; < properties.settings.default.useraccounts.count; i++) { xml_settings_file.writeelementstring("account", system.security.securityelement.escape(properties.settings.default.useraccounts[i].tostring())); xml_settings_file.writeelementstring("file", system.security.securityelement.escape(properties.settings.default.filepaths[i])); } xml_settings_file.writeendelement(); xml_settings_file.flush(); } }
to create things more confusing, when replace filepath variable simple "test" string, works fine , file created no problems.
please seek using cdata instead of escaping path characters.
you can replace:
xml_settings_file.writeelementstring("file", system.security.securityelement.escape(properties.settings.default.filepaths[i]));
with next lines:
xml_settings_file.writestartelement("file"); xml_settings_file.writecdata(properties.settings.default.filepaths[i]); xml_settings_file.writeendelement();
c# xml file xmlwriter
Comments
Post a Comment