Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could probably write a simple class, for example I use a Speech class like this one:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Serialization; namespace StackOverflowSamples { [Serializable] public class Speech { public Speech() { this.Items = new List&lt;LanguageItem&gt;(); } [XmlArray] public List&lt;LanguageItem&gt; Items; } [Serializable] public class LanguageItem { [XmlAttribute] public string Language { get; set; } [XmlAttribute] public int Id { get; set; } } } </code></pre> <p>Which can be simply serialized with this code:</p> <pre><code>// use built in serialization mechanism XmlSerializer mySerializer = new XmlSerializer(typeof(Speech)); // Writing the file requires a TextWriter. TextWriter writer = new StreamWriter("test.xml"); var speech = new Speech(); var lang1 = new LanguageItem() { Id = 1, Language = "English", }; var lang2 = new LanguageItem() { Id = 2, Language = "Slovenian", }; speech.Items.Add(lang1); speech.Items.Add(lang2); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); //Add an empty namespace and empty value ns.Add("", ""); mySerializer.Serialize(writer, speech, ns); writer.Close(); </code></pre> <p>Resulting in XML like this here:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Speech&gt; &lt;Items&gt; &lt;LanguageItem Language="English" Id="1" /&gt; &lt;LanguageItem Language="Slovenian" Id="2" /&gt; &lt;/Items&gt; &lt;/Speech&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload