首页
论坛
新职位
搜索论坛
什么's new
新职位
新的个人资料帖子
最新活动
会员
目前的访客
新的个人资料帖子
搜索个人资料帖子
VB.NET社区
登录
登记
什么's new
搜索
搜索
仅搜索标题
经过:
新职位
搜索论坛
Menu
Log in
Register
安装应用
安装
首页
论坛
数据库
XML格式
从数据表在xml文档中创建重复元素
您正在使用过期的浏览器。它可能无法正确显示此网站或其他网站。
您应该升级或使用
替代浏览器
.
回复主题
信息
<blockquote data-quote="chester" data-source="post: 5274" data-attributes="member: 9636"><p>Hi all,</p><p></p><p>I am creating an XML document from a schema. I used xsd.exe to create a class file from the xsd. I have a datatable that I am using to write the xml with. Below is a sample with only first name and surname. </p><p></p><p>As expected though, 5 nodes are created, the problem is that it only writes the last item from the datatable. What do I need to change? </p><p></p><p>[CODE]XmlSerializerNamespaces ns = new XmlSerializerNamespaces();</p><p></p><p> XmlSerializer serializer = new XmlSerializer(typeof(UKFATCASubmissionFIReport));</p><p> TextWriter writer = new StreamWriter(destinationPath);</p><p> UKFATCASubmissionFIReport fatcaSub = new UKFATCASubmissionFIReport();</p><p> fatcaSub.SchemaVersion = schemaVersion;</p><p></p><p> //Initialize classes and objects</p><p> #region classes and objects</p><p></p><p> AccountDataType accountData = new AccountDataType();</p><p> AccountHolderCodeType accountHolderType = new AccountHolderCodeType();</p><p> MessageDataType messageData = new MessageDataType();</p><p> MonetaryType moneyType = new MonetaryType();</p><p> SubmissionType submissionData = new SubmissionType();</p><p> FIReturnActionType fireturnActionData = new FIReturnActionType();</p><p> AccountActionType accountActionData = new AccountActionType();</p><p> TINCodeType tinCode = new TINCodeType();</p><p> HolderTaxInfoType holderInfo = new HolderTaxInfoType();</p><p> //PaymentDataType paymentData = paymentDetails();</p><p> </p><p> </p><p> #endregion</p><p></p><p></p><p> //Monetary type</p><p> moneyType.Value = moneyTypeValue;</p><p> moneyType.currCode = currCode_Type.GBP;</p><p></p><p> //Create message data</p><p> messageData.FATCAUserId = FatcaUserID;</p><p> messageData.XMLTimeStamp = timeStamp;</p><p> messageData.MessageCategory = MessageType.NewSubmission;</p><p> fatcaSub.MessageData = messageData;</p><p></p><p> //Create submission data object</p><p> submissionData.ReportingPeriod = reportingPeriod;</p><p> submissionData.Item = messageRef;</p><p> fatcaSub.Item = submissionData;</p><p></p><p> //FI Return Action</p><p></p><p> fireturnActionData.Action = ActionType.New;</p><p> fireturnActionData.FIReturnRef = returnRef;</p><p></p><p> //FIReturnActionType[] fireturnItems = new FIReturnActionType[] { fireturnActionData };</p><p> //TIN Code Type</p><p> tinCode.TINCountryCode = countryCode;</p><p> tinCode.Value = tinCodeValue;</p><p> tinCode.TINCountryCodeSpecified = itemSpecified;</p><p></p><p> //TIN Information</p><p> holderInfo.ReportableJurisdiction = countryCode;</p><p> holderInfo.TIN = holderTIN;</p><p> holderInfo.TINCode = tinCode;</p><p></p><p> //ContactPersonInformation contactInfo = ContactInformation(holderInfo);</p><p> //Contact address</p><p> ContactAddressType contactAddress = new ContactAddressType();</p><p> contactAddress.StreetName = streetName;</p><p> contactAddress.City = contactCity;</p><p> contactAddress.CountryCode = holderInfo.ReportableJurisdiction;</p><p></p><p> //Person Details</p><p> ContactPersonInformation contactInfo = new ContactPersonInformation();</p><p> //contactInfo.FirstName = firstName;</p><p> contactInfo.LastName = lastName;</p><p> contactInfo.Address = contactAddress;</p><p> contactInfo.HolderTaxInfo = holderInfo;</p><p> contactInfo.BirthDateSpecified = itemSpecified;</p><p> contactInfo.BirthDate = dateOfBirth;</p><p></p><p> PaymentMonetaryType paymentMonetary = new PaymentMonetaryType();</p><p> paymentMonetary.currCode = currCode_Type.GBP;</p><p> paymentMonetary.Value = paymentValue;</p><p></p><p> //Payment data object</p><p> PaymentDataType paymentData = new PaymentDataType();</p><p> paymentData.PaymentCode = PaymentCodeType.Item20;</p><p> paymentData.PaymentAmount = paymentMonetary;</p><p> //return paymentData;</p><p></p><p> //Account action</p><p> accountActionData.AccountRef = accountRef;</p><p> accountActionData.Action = ActionType.New;</p><p> </p><p> //Account information array</p><p> //AccountData(paymentData, contactInfo, accountActionData, accountData, accountHolderType);</p><p></p><p> object[] accountItems = new object[] { accountActionData, accountNumber, paymentData, accountHolderType, contactInfo };</p><p> accountData.Items = accountItems;</p><p></p><p> ItemsChoiceType[] accountFieldNames = new ItemsChoiceType[] { ItemsChoiceType.AccountAction, ItemsChoiceType.AccountNumber, ItemsChoiceType.PaymentData, ItemsChoiceType.AccountHolderType, ItemsChoiceType.Person };</p><p> accountData.ItemsElementName = accountFieldNames;</p><p></p><p> DataTable dtTable = new DataTable();</p><p> dtTable.Columns.Add("FirstName", typeof(string));</p><p> dtTable.Columns.Add("Surname", typeof(string));</p><p></p><p> // Here we add five DataRows.</p><p> dtTable.Rows.Add("Test", "Test");</p><p> dtTable.Rows.Add("Two", "Three");</p><p> dtTable.Rows.Add("Four", "Five");</p><p> dtTable.Rows.Add("Six", "Seven");</p><p> dtTable.Rows.Add("Eight", "Nine");</p><p></p><p></p><p> List<FIReturnType> fiRetList = new List<FIReturnType>();</p><p> foreach (DataRow row in dtTable.Rows)</p><p></p><p> {</p><p> object fName = row["FirstName"];</p><p> object sName = row["Surname"];</p><p> contactInfo.FirstName = fName.ToString();</p><p> contactInfo.LastName = sName.ToString();</p><p> </p><p> FIReturnType fireturn = new FIReturnType();</p><p> object[] fiItems = new object[] { fireturnActionData, fiRegisterID, dueDilligenceInd, thresholdInd, accountData };</p><p> fireturn.Items = fiItems;</p><p></p><p> ItemsChoiceType1[] fiFieldnames = new ItemsChoiceType1[] { ItemsChoiceType1.FIReturnAction, ItemsChoiceType1.FIRegisterId, ItemsChoiceType1.DueDiligenceInd, ItemsChoiceType1.ThresholdInd, ItemsChoiceType1.AccountData };</p><p> fireturn.ItemsElementName = fiFieldnames;</p><p></p><p> fiRetList.Add(new FIReturnType { Items = fiItems, ItemsElementName = fiFieldnames });</p><p></p><p> FIReturnType[] fiData = fiRetList.ToArray();</p><p> </p><p> submissionData.FIReturn = fiData;</p><p>}</p><p> //Serialize the submission close the TextWriter</p><p></p><p> serializer.Serialize(writer, fatcaSub);</p><p> </p><p> writer.Close();[/CODE]</p></blockquote><p></p>
Insert quotes…
确认
发表回复
首页
论坛
数据库
XML格式
从数据表在xml文档中创建重复元素
本网站使用Cookie来帮助个性化内容,调整您的体验并在注册时保持登录状态。
继续使用本网站,即表示您同意我们使用cookie。
接受
了解更多…
最佳
底部