public static void Main()
var classTextXml = @"<NewBusiness specialaccess='false' search='true' readonly='false' top='true' table='NEWBUS_TABLE' data-object='newbus'><ALLRequirementsIn type='date' search='false' readonly='true' col='NEWBUS_ALLRequirementsIn'/><AgencyRep type='object' search='true' readonly='false' col='NEWBUS_AgencyRep' obj='User'/><AgencyRepID type='id' search='true' readonly='false' col='NEWBUS_AgencyRep' obj='User'/><AgencyRepRef length='60' type='string' search='false' readonly='true' col='NEWBUS_AgencyRepRef'/><AgencyRepValue type='integer' search='false' readonly='false' col='NEWBUS_AgencyRep'/><AlphaNum1 length='255' type='string' search='true' readonly='false' col='NEWBUS_ALPHANUM1'/><Alternate type='integer' search='false' readonly='false' col='NEWBUS_Alternate'/><AnnPrem type='double' search='false' readonly='false' col='NEWBUS_AnnPrem'/><AnnualNonCommFee type='double' search='false' readonly='false' col='NEWBUS_AnnualNonCommFee'/><AnnualPlcyFee type='double' search='false' readonly='false' col='NEWBUS_AnnualPlcyFee'/><AppSigned type='date' search='false' readonly='true' col='NEWBUS_AppSigned'/><Approved type='date' search='false' readonly='true' col='NEWBUS_Approved'/><AsOfDate type='datetime' search='false' readonly='true' col='NEWBUS_AsOfDate'/><Benefit type='double' search='false' readonly='false' col='NEWBUS_Benefit'/><CaseNumber length='30' type='string' search='true' readonly='false' col='NEWBUS_CaseNumber'/><CashReceived type='double' search='false' readonly='false' col='NEWBUS_CashReceived'/><CommAnnPrem type='double' search='false' readonly='false' col='NEWBUS_CommAnnPrem'/><CommModal type='double' search='false' readonly='false' col='NEWBUS_CommModal'/><CommPrem type='double' search='false' readonly='false' col='NEWBUS_COMMPREM'/><Contact type='object' search='false' readonly='false' col='HOLDING_ContactID' obj='Contact'/><ContactID type='id' search='false' readonly='false' col='HOLDING_ContactID' obj='Contact'/><CustomData obj='CustomData' link='CustomData.ObjectID'/><DataProvider length='255' type='string' search='true' readonly='false' col='HOLDING_DataProvider'/><DateCalculated type='byte' search='false' readonly='true' col='NEWBUS_DateCalculated'/><Delivered type='date' search='false' readonly='true' col='NEWBUS_Delivered'/><ECPUniqueID length='64' type='string' search='true' readonly='false' col='NEWBUS_ECPUniqueID'/><EX1035Prem type='double' search='false' readonly='false' col='NEWBUS_EX1035PREM'/><ExcessPrem type='double' search='false' readonly='false' col='NEWBUS_ExcessPrem'/><FYC type='double' search='false' readonly='false' col='NEWBUS_FYC'/><FlatExtra type='double' search='false' readonly='false' col='NEWBUS_FLATEXTRA'/><FlatExtraPerThousand type='double' search='false' readonly='false' col='NEWBUS_FlatExtraPerThousand'/><FlatExtraPeriod type='lookup' lookupId='2138' search='false' readonly='false' col='NEWBUS_FEPeriod'/><HONewBusinesses obj='HONewBusiness' link='HONewBusiness.HoldingID'/><HORep type='object' search='false' readonly='false' col='NEWBUS_HomeRep' obj='HORep'/><HoldingID type='integer' search='false' readonly='false' col='HOLDING_HoldingID'/><HoldingType type='lookup' lookupId='33' search='true' readonly='false' col='HOLDING_HoldingType'/><Inforce type='date' search='false' readonly='true' col='NEWBUS_Inforce'/><InforceRequest type='lookup' lookupId='70' search='false' readonly='false' col='NEWBUS_InforceRequest'/><InforceRequestText type='lookuptext' search='false' readonly='true' col='NEWBUS_InforceRequestText'/><IsCommFlatExtra type='lookup' lookupId='2' search='false' readonly='false' col='NEWBUS_IsCommFlatExtra'/><IsCommPolicyFee type='lookup' lookupId='2' search='false' readonly='false' col='NEWBUS_IsCommPolicyFee'/><Issued type='date' search='false' readonly='true' col='NEWBUS_Issued'/><LumpSum type='double' search='false' readonly='false' col='NEWBUS_LumpSum'/><ModalFactor type='double' search='false' readonly='false' col='NEWBUS_ModalFactor'/><ModifiedOn type='datetime' search='true' readonly='false' col='NEWBUS_ModifiedOn'/><NBDelivery obj='NBDelivery' link='NBDelivery.HoldingID'/><NBHistorys obj='NBHistory' link='NBHistory.HoldingID'/><NextFollowup type='date' search='false' readonly='true' col='NEWBUS_NextFollowup'/><NonCommFee type='double' search='false' readonly='false' col='NEWBUS_NonCommFee'/><PaymentMethod type='lookup' lookupId='387' search='false' readonly='false' col='NEWBUS_PaymentMethod'/><Policy obj='Policy'/><PolicyFee type='double' search='false' readonly='false' col='NEWBUS_POLICYFEE'/><Prem type='double' search='false' readonly='false' col='NEWBUS_Prem'/><PremMode type='lookup' lookupId='38' search='false' readonly='false' col='NEWBUS_PremMode'/><Premium type='double' search='false' readonly='false' col='NEWBUS_PREMIUM'/><ProcessingType type='lookup' lookupId='2511' search='true' readonly='false' col='NEWBUS_PROCESSINGTYPE'/><ProductType type='lookup' lookupId='39' search='false' readonly='false' col='NEWBUS_ProductType'/><Renewal type='double' search='false' readonly='false' col='NEWBUS_Renewal'/><Requirements obj='Requirement' link='Requirement.PolicyID'/><SPHandling type='lookup' lookupId='2' search='false' readonly='false' col='NEWBUS_SPHandling'/><SourceOfDataType type='lookup' lookupId='308' search='true' readonly='false' col='HOLDING_SourceOfDataType'/><Stage type='lookup' lookupId='72' search='true' readonly='false' col='POLICY_Stage'/><Submitted type='date' search='false' readonly='true' col='NEWBUS_Submitted'/><TargetAmt type='double' search='false' readonly='false' col='NEWBUS_TARGETAMT'/><TeamText length='200' type='string' search='false' readonly='true' col='NEWBUS_TeamText'/><UnderWriter type='object' search='false' readonly='false' col='NEWBUS_UnderWriter' obj='UnderWriter'/><WaivePolicyFee type='byte' search='false' readonly='false' col='NEWBUS_WaivePolicyFee'/></NewBusiness>";
var classText = ClassCreatorUtility.textOfClass(classTextXml);
Console.WriteLine(classText);
public static class ClassCreatorUtility
public static string textOfClass(string xml)
var classDefinition = string.Empty;
XmlDocument xmldoc = new XmlDocument();
var xmlObject = xmldoc.SelectNodes("*");
foreach (XmlNode node in xmlObject)
classDefinition = string.Format("[XmlRoot(\"{0}\")]{1}public class {2}", node.Name, Environment.NewLine, node.Name);
classDefinition += "{" + Environment.NewLine;
foreach (XmlNode properties in node.ChildNodes)
classDefinition += Environment.NewLine;
var custPropType = string.Empty;
var custPropName = string.Empty;
var className = string.Empty;
if (properties.Attributes["type"] != null)
custPropType = properties.Attributes["type"].Value;
custPropType = "DateTime";
custPropType = "DateTime";
custPropType = properties.Attributes["obj"].Value;
className = properties.Attributes["obj"].Value;
custPropType = string.Format("List<{0}>", properties.Attributes["obj"].Value);
else if (properties.Attributes["obj"] != null)
custPropType = properties.Attributes["obj"].Value;
if (properties.Attributes["ReferredById"] != null || properties.Attributes["ReferredByObj"] != null)
custPropName = properties.Attributes["col"].Value;
custPropName = properties.Name;
if (custPropName.Equals(custPropType))
classDefinition += string.Format("[XmlElement(\"{0}\", typeof({0}))]{1}", custPropName, Environment.NewLine);
classDefinition += string.Format("public {0} {1} ", custPropType, custPropName);
classDefinition += "{ get; set; }" + Environment.NewLine;
else if (custPropType.Contains("List"))
classDefinition += string.Format("[XmlElement(\"{0}\", typeof({1}))]{2}", custPropName, className, Environment.NewLine);
classDefinition += string.Format("public {0} {1} ", custPropType, custPropName);
classDefinition += "{ get; set; }" + Environment.NewLine;
if (custPropType.Equals("int") | custPropType.Equals("short") | custPropType.Equals("byte") | custPropType.Equals("double") | custPropType.Equals("DateTime"))
classDefinition += "[XmlIgnore]" + Environment.NewLine;
classDefinition += string.Format("public {0}? {1}", custPropType, custPropName);
classDefinition += " { get; set; }" + Environment.NewLine;
classDefinition += Environment.NewLine + string.Format("[XmlElement(\"{0}\")]{1}", custPropName, Environment.NewLine);
classDefinition += string.Format("public {0} {1} ", custPropType, custPropName + "Serializable");
classDefinition += Environment.NewLine + "{" + Environment.NewLine;
classDefinition += "\t get { " + string.Format("return this.{0}.Value; ", custPropName) + "}" + Environment.NewLine;
classDefinition += "\t set { " + string.Format("this.{0} = value; ", custPropName) + "}";
classDefinition += Environment.NewLine + "}" + Environment.NewLine;
classDefinition += Environment.NewLine + string.Format("public bool ShouldSerialize{0}Serializable()", custPropName);
classDefinition += Environment.NewLine + "{" + Environment.NewLine;
classDefinition += string.Format("\t return {0}.HasValue; ", custPropName);
classDefinition += Environment.NewLine + "}" + Environment.NewLine;
classDefinition += string.Format("[XmlElement(\"{0}\")]{1}", custPropName, Environment.NewLine);
classDefinition += string.Format("public {0} {1} ", custPropType, custPropName);
classDefinition += "{ get; set; }" + Environment.NewLine;