Good day,
I have a problem with a project I am busy with. I am creating an XML document from a predefined schema. I am able to this with no problem for one level using this method:
{ XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); XmlSerializer serializer = new XmlSerializer(typeof(UKFATCASubmissionFIReport)); TextWriter writer = new StreamWriter(destinationPath); UKFATCASubmissionFIReport fatcaSub = new UKFATCASubmissionFIReport(); fatcaSub.SchemaVersion = schemaVersion; //Initialize classes and objects #region classes and objects AccountDataType accountData = new AccountDataType(); AccountHolderCodeType accountHolderType = new AccountHolderCodeType(); MessageDataType messageData = new MessageDataType(); MonetaryType moneyType = new MonetaryType(); SubmissionType submissionData = new SubmissionType(); FIReturnActionType fireturnActionData = new FIReturnActionType(); AccountActionType accountActionData = new AccountActionType(); TINCodeType tinCode = new TINCodeType(); HolderTaxInfoType holderInfo = new HolderTaxInfoType(); //PaymentDataType paymentData = paymentDetails(); #endregion //Monetary type moneyType.Value = moneyTypeValue; moneyType.currCode = currCode_Type.GBP; //Create message data messageData.FATCAUserId = FatcaUserID; messageData.XMLTimeStamp = timeStamp; messageData.MessageCategory = MessageType.NewSubmission; fatcaSub.MessageData = messageData; //Create submission data object submissionData.ReportingPeriod = reportingPeriod; submissionData.Item = messageRef; fatcaSub.Item = submissionData; //FI Return Action fireturnActionData.Action = ActionType.New; fireturnActionData.FIReturnRef = returnRef; //FIReturnActionType[] fireturnItems = new FIReturnActionType[] { fireturnActionData }; //TIN Code Type tinCode.TINCountryCode = countryCode; tinCode.Value = tinCodeValue; tinCode.TINCountryCodeSpecified = itemSpecified; //TIN Information holderInfo.ReportableJurisdiction = countryCode; holderInfo.TIN = holderTIN; holderInfo.TINCode = tinCode; //ContactPersonInformation contactInfo = ContactInformation(holderInfo); //Contact address ContactAddressType contactAddress = new ContactAddressType(); contactAddress.StreetName = streetName; contactAddress.City = contactCity; contactAddress.CountryCode = holderInfo.ReportableJurisdiction; //Person Details ContactPersonInformation contactInfo = new ContactPersonInformation(); contactInfo.FirstName = firstName; contactInfo.LastName = lastName; contactInfo.Address = contactAddress; contactInfo.HolderTaxInfo = holderInfo; contactInfo.BirthDateSpecified = itemSpecified; contactInfo.BirthDate = dateOfBirth; PaymentMonetaryType paymentMonetary = new PaymentMonetaryType(); paymentMonetary.currCode = currCode_Type.GBP; paymentMonetary.Value = paymentValue; //Payment data object PaymentDataType paymentData = new PaymentDataType(); paymentData.PaymentCode = PaymentCodeType.Item20; paymentData.PaymentAmount = paymentMonetary; //return paymentData; //Account action accountActionData.AccountRef = accountRef; accountActionData.Action = ActionType.New; //Account information array //AccountData(paymentData, contactInfo, accountActionData, accountData, accountHolderType); object[] accountItems = new object[] { accountActionData, accountNumber, paymentData, accountHolderType, contactInfo }; accountData.Items = accountItems; ItemsChoiceType[] accountFieldNames = new ItemsChoiceType[] { ItemsChoiceType.AccountAction, ItemsChoiceType.AccountNumber, ItemsChoiceType.PaymentData, ItemsChoiceType.AccountHolderType, ItemsChoiceType.Person }; accountData.ItemsElementName = accountFieldNames; //Financial Information Return main array //FIReturn(submissionData, fireturnActionData, accountData); FIReturnType fireturn = new FIReturnType(); object[] fiItems = new object[] { fireturnActionData, fiRegisterID, dueDilligenceInd, thresholdInd, accountData }; fireturn.Items = fiItems; ItemsChoiceType1[] fiFieldnames = new ItemsChoiceType1[] { ItemsChoiceType1.FIReturnAction, ItemsChoiceType1.FIRegisterId, ItemsChoiceType1.DueDiligenceInd, ItemsChoiceType1.ThresholdInd, ItemsChoiceType1.AccountData }; fireturn.ItemsElementName = fiFieldnames; FIReturnType[] fiData = new FIReturnType[] { fireturn }; //Map FI return data to submissionData submissionData.FIReturn = fiData; //Serialize the submission close the TextWriter serializer.Serialize(writer, fatcaSub); writer.Close(); Process.Visible = false; MessageBox.Show("Processing Complete!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); Close(); }
The problem is that I would like fireturn to appear in the document more than once from a dataset. If I changed my code to this:
FIReturnType[] fiData = new FIReturnType[] { fireturn, fireturn, fireturn }; //Map FI return data to submissionData submissionData.FIReturn = fiData;
I am able to get the three elements as required. How can I change my code to allow for a foreach statement for example?