KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'd like to serialize a class to XML, assigning an XML attribute to it. Snippet: [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 well and good, with the only exception being that myClass2.Name is not serialized. I was expecting something in the line of <classmy myattr="nomm" [...]>[...]</classmy> ... Why isn't that serialized, and how can it be?
Tags (comma-separated)
Save Edits
Cancel