XML Serialization suppressing separate nodes for each class

HneO

New Member
I am trying to convert a multiple record flat file to xml. I have a separate class for each record type. Some of the classes will only have one instance and don't need to be separated by a "class node". Some have multiple occurances and do need to be separated. I can't find any help on ignoring/removing the class name when using xml serializer.\[code\]public class Class1{ public string StringA; public string StringB; public string StringC;}public class Class2{ public string StringD; public string StringE; public string StringF;} public class Class3{ public string Name; public Class1 User1 = new Class1 { StringA = "A String", StringB = "B String", StringC = "C String" }; public Class2 User2 = new Class2 { StringD = "D String", StringE = "E String", StringF = "F String" };}\[/code\]Here is the serialization:\[code\]XmlSerializer x = new XmlSerializer(typeof(Class3));var test = new Class3();test.Name = "Name";x.Serialize(Console.Out, test);\[/code\]I get the following:\[code\]<Class3><Name>Name</Name> <User1> <StringA>A String</StringA> <StringB>B String</StringB> <StringC>C String</StringC> </User1><User2> <StringD>D String</StringD> <StringE>E String</StringE> <StringF>F String</StringF> </User2>\[/code\]I want the and nodes to disapear and become:\[code\]<Class3> <Name>Name</Name> <StringA>A String</StringA> <StringB>B String</StringB> <StringC>C String</StringC> <StringD>D String</StringD> <StringE>E String</StringE> <StringF>F String</StringF></Class3>\[/code\]
 
Back
Top