I would like to serialize the class in XML by assigning it an XML attribute. Excerpt:
[XmlType(TypeName = "classmy")] public class MyClass2 : List<object> { [XmlAttribute(AttributeName = "myattr")] public string Name { get; set; } } public class MyConst { public MyConst() { MyClass2 myClass2 = new MyClass2 { 10, "abc" }; myClass2.Name = "nomm"; XmlSerializer serializer = new XmlSerializer(typeof(MyClass2)); serializer.Serialize(Console.Out, myClass2); } }
But the resulting XML looks like this:
<?xml version="1.0" encoding="IBM437"?> <classmy xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <anyType xsi:type="xsd:int">10</anyType> <anyType xsi:type="xsd:string">abc</anyType> </classmy>
All is well and good, except that myClass2.Name is not serialized. I was expecting something on the line
<classmy myattr="nomm" [...]>[...]</classmy>
... Why is it not serialized and how can it be?
user377486
source share