The Account element under GeneralLedgerAccounts is presumably because its the name of the member of GeneralLedgerAccounts. Perhaps if you change GeneralLedgerAccounts to derive from a List<Account> rather than have a member of that type, that will give you the structure you want.
Serializing a list of objects
TRAIAN MACAVEIU
91
Reputation points
Hello people!
I have a structure of the form:
public class MasterFiles
{
public GeneralLedgerAccounts GeneralLedgerAccounts { get; set; }
public Customers Customers { get; set; }
public Suppliers Suppliers { get; set; }
public TaxTable TaxTable { get; set; }
public UOMTable UOMTable { get; set; }
public AnalysisTypeTable AnalysisTypeTable { get; set; }
public string MovementTypeTable { get; set; }
public Products Products { get; set; }
public string Owners { get; set; }
public string Assets { get; set; }
}
public class Account
{
public string AccountID { get; set; }
public string AccountDescription { get; set; }
public string StandardAccountID { get; set; }
public string AccountType { get; set; }
public string AccountCreationDate { get; set; }
public string OpeningCreditBalance { get; set; }
public string ClosingCreditBalance { get; set; }
public string OpeningDebitBalance { get; set; }
public string ClosingDebitBalance { get; set; }
}
public class GeneralLedgerAccounts
{
public List<Account> Account { get; set; }
}
data completion:
GeneralLedgerAccounts gla = new GeneralLedgerAccounts();
gla.Account = new List<Account>();
gla.Account.Add(new Account()
{
AccountID = "1", ...
});
masterfiles.GeneralLedgerAccounts = gla;
after serialization, I get an XML file with the following structure:
<nsSAFT:MasterFiles>
<nsSAFT:GeneralLedgerAccounts>
<nsSAFT:Account>
<nsSAFT:Account>
<nsSAFT:AccountID>1</nsSAFT:AccountID>
</nsSAFT:Account>
</nsSAFT:Account>
</nsSAFT:GeneralLedgerAccounts>dgerAccounts>
</nsSAFT:MasterFiles>
what am I doing wrong because the desired structure should look like this:
<nsSAFT:MasterFiles>
<nsSAFT:GeneralLedgerAccounts>
<nsSAFT:Account>
<nsSAFT:AccountID>1</nsSAFT:AccountID>
</nsSAFT:Account>
</nsSAFT:GeneralLedgerAccounts>
</nsSAFT:MasterFiles>
Thank you for the answers!