Hello,
I need this one.
<GROUP>
<TASK>
<NAME value="Receiver Serial number" />
<QUANTITY value="67" />
//..//.
<PRICE value="63 €" />
</TASK>
</GROUP>
I got this.
<GROUP>
<TASK>
<KeyValue value="Receiver Serial number">
<Key>Name</Key>
</KeyValue>
<KeyValue value="67">
<Key>Quantiy</Key>
</KeyValue>
</TASK>
</GROUP>
What is wrong, how can I solve it well?
That is my code!
public class HelperTest
{
private static readonly XmlWriterSettings WriterSettingsExclusiv = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true, Encoding = new UTF8Encoding(true) };
private static readonly XmlSerializerNamespaces Namespaces = new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", ""), });
[XmlElement]
public Group Group { get; set; }
public void SaveTraceXML<T>(string file, T dataObject)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (Stream stream = new FileStream(file, FileMode.Create))
using (XmlWriter xmlWriter = XmlWriter.Create(stream, WriterSettingsExclusiv))
{
serializer.Serialize(xmlWriter, dataObject, Namespaces);
}
}
}
//[XmlRoot("GROUP")]
//[XmlElement(@"Key")]
public class KeyValue
{
[XmlElement]
//[XmlAttribute("key")]
public string Key { get; set; }
[XmlAttribute("value")]
public string Value { get; set; }
}
[XmlRoot("GROUP")]
public class Group
{
//[XmlElement("TASK")]
//public Dictionary<string, KeyValue> Task { get; set; }
[XmlArray("TASK")]
//[XmlArrayItem("Side")]
public List<KeyValue> ListTaskElements { get; set; }
// public SerializableDictionary<string, KeyValue> Task2 { get; set; }
}
// *** from Main Window!
HelperTest ht = new HelperTest();
ht.Group = new Group();
ht.Group.ListTaskElements = new System.Collections.Generic.List<KeyValue>();
ht.Group.ListTaskElements.Add(new KeyValue() { Key = "Name", Value = "Receiver Serial number" });
ht.Group.ListTaskElements.Add(new KeyValue() { Key = "Quantiy", Value = "67" });
ht.SaveTraceXML(@"C:\Temp\TTTTTT.XML", ht.Group);
Thanks for your help in advance!