Мне нужно сгенерировать XML из заполненного класса.
Я сделал:
[XmlRoot(Namespace = ""), Serializable()]
public class FormBuilderDataset
{
public FormBuilderDataset()
{
this.Form_template = new Form_template();
this.Form_template_header = new Form_template_header();
this.Form_template_footer = new Form_template_footer();
this.Sections = new List<Sections> { };
this.Section_form = new List<Section_form> { };
this.Categories = new List<Categories> { };
this.Element_category = new List<Element_category> { };
this.Elements = new List<Elements> { };
this.Answers = new List<Answers> { };
this.Calculation_methods_scores = new List<Calculation_methods_scores> { };
this.Defaults = new List<Defaults> { };
this.Rules = new List<Rules> { };
this.Rules_actions = new List<Rules_actions> { };
this.Category_section = new List<Category_section> { };
}
[XmlElement(ElementName = "Form_template")]
public Form_template Form_template { get; set; }
[XmlElement(ElementName = "Form_template_header")]
public Form_template_header Form_template_header { get; set; }
[XmlElement(ElementName = "Form_template_footer")]
public Form_template_footer Form_template_footer { get; set; }
[XmlElement(ElementName = "Sections")]
public List<Sections> Sections { get; set; }
[XmlElement(ElementName = "Section_form")]
public List<Section_form> Section_form { get; set; }
[XmlElement(ElementName = "Categories")]
public List<Categories> Categories { get; set; }
[XmlElement(ElementName = "Element_category")]
public List<Element_category> Element_category { get; set; }
[XmlElement(ElementName = "Elements")]
public List<Elements> Elements { get; set; }
[XmlElement(ElementName = "Answers")]
public List<Answers> Answers { get; set; }
[XmlElement(ElementName = "Calculation_methods_scores")]
public List<Calculation_methods_scores> Calculation_methods_scores { get; set; }
[XmlElement(ElementName = "Defaults")]
public List<Defaults> Defaults { get; set; }
[XmlElement(ElementName = "Rules")]
public List<Rules> Rules { get; set; }
[XmlElement(ElementName = "Rules_actions")]
public List<Rules_actions> Rules_actions { get; set; }
[XmlElement(ElementName = "Category_section")]
public List<Category_section> Category_section { get; set; }
}
и после заполнения класса я попытался:
XmlSerializer serializer = new XmlSerializer(typeof(FormBuilderDataset));
XmlWriterSettings settings = new XmlWriterSettings()
{
Indent = true,
OmitXmlDeclaration = false
};
TextWriter stream = new StreamWriter(fileName);
XmlWriter writer = XmlWriter.Create(stream, settings);
serializer.Serialize(writer, form, new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }));
writer.Close();
stream.Close();
Но я получаю:
<?xml version="1.0" encoding="utf-8"?>
<FormBuilderDataset>
<Form_template>
<form_template_guid>eed0cb1e-2e60-44b4-a544-b2cbfa15001c</form_template_guid>
<form_template_name>SEM PARAR || SINERGIA V2</form_template_name>
<form_type_id>1</form_type_id>
<calculated_score_guid>1c8ce250-7bc6-43a5-bf77-bfff72c0f8f5</calculated_score_guid>
<displayed_max_score>0</displayed_max_score>
<is_max_scored_displayed>false</is_max_scored_displayed>
<has_auto_kpi>false</has_auto_kpi>
<kpi_version>0</kpi_version>
<kpi_creation_status>0</kpi_creation_status>
<description>SEM PARAR || SINERGIA V2</description>
...
Я хотел бы вернуть:
<?xml version="1.0" standalone="yes"?>
<FormBuilderDataset xmlns="http://tempuri.org/FormBuilderDataset.xsd">
<Form_template>
<form_template_guid>eed0cb1e-2e60-44b4-a544-b2cbfa15001c</form_template_guid>
<form_template_name>SEM PARAR || SINERGIA V2</form_template_name>
<form_type_id>1</form_type_id>
<calculated_score_guid>1c8ce250-7bc6-43a5-bf77-bfff72c0f8f5</calculated_score_guid>
<displayed_max_score>0</displayed_max_score>
<is_max_scored_displayed>false</is_max_scored_displayed>
<has_auto_kpi>false</has_auto_kpi>
<kpi_version>0</kpi_version>
<kpi_creation_status>0</kpi_creation_status>
<description>SEM PARAR || SINERGIA V2</description>
..
ИтакЯ хотел бы добавить свойство standalone = "yes" в узел xml вместо encoding = "utf-8" и добавить xmlns = "http://tempuri.org/FormBuilderDataset.xsd" в узел FormBuilderDataset.
Может ли кто-нибудь мне помочь?