抱歉,这是新手... 我有一个XSD文件,该文件曾经使用XSD.exe在C#中创建类。 现在的挑战是试图弄清楚如何手动填充对象,以便随后可以序列化为XML(我没有源XML文件,因此需要通过备用源手动设置属性)。
以下是从XSD文件生成的示例类。我可以设置文件摘要和债务人信息,但不知道如何设置债务人联系信息。
<?xml version="1.0" encoding="utf-8"?>
<FileSummary FileDate="1900-01-01T01:01:01+08:00" OpeningBalance="1" Invoices="1" DebitNotes="1" CreditNotes="1" CashReceipts="1" OtherPositive="1" OtherNegative="1" ClosingBalance="1">
<Debtor DebtorId="DebtorId2" DebtorName="DebtorName2" ExcludedDebtor="ExcludedDebtor2" CreditLimit="-79228162514264337593543950335" DebtorStatus="DebtorStatus2" TradingTerms="TradingTerms2" OverduePeriod="4294967295" HeadOfficeCode="HeadOfficeCode2" HeadOfficeName="HeadOfficeName2" DebtorCountry="DebtorCountry2" ABN="ABN2" ARBN="ARBN2" ACN="ACN2" LegalName="LegalName2" MainTradingName="MainTradingName2" OtherTradingName="OtherTradingName2">
<DebtorContact Surname="Surname4" FirstName="FirstName4" OtherNames="OtherNames4" Phone="Phone4" Mobile="Mobile4" Fax="Fax4" Email="Email4" Salutation="Salutation4" JobTitle="JobTitle4" ContactAddress="ContactAddress4" ContactSuburb="ContactSuburb4" ContactCountry="ContactCountry4" ContactState="ContactState4" ContactPostcode="ContactPostcode4" />
<DebtorContact Surname="Surname5" FirstName="FirstName5" OtherNames="OtherNames5" Phone="Phone5" Mobile="Mobile5" Fax="Fax5" Email="Email5" Salutation="Salutation5" JobTitle="JobTitle5" ContactAddress="ContactAddress5" ContactSuburb="ContactSuburb5" ContactCountry="ContactCountry5" ContactState="ContactState5" ContactPostcode="ContactPostcode5" />
</Debtor>
</FileSummary>
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=4.6.1055.0.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class FileSummary {
private FileSummaryDebtor[] debtorField;
private System.DateTime fileDateField;
private decimal openingBalanceField;
private decimal invoicesField;
private decimal debitNotesField;
private decimal creditNotesField;
private decimal cashReceiptsField;
private decimal otherPositiveField;
private decimal otherNegativeField;
private decimal closingBalanceField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Debtor")]
public FileSummaryDebtor[] Debtor {
get {
return this.debtorField;
}
set {
this.debtorField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.DateTime FileDate {
get {
return this.fileDateField;
}
set {
this.fileDateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal OpeningBalance {
get {
return this.openingBalanceField;
}
set {
this.openingBalanceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal Invoices {
get {
return this.invoicesField;
}
set {
this.invoicesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal DebitNotes {
get {
return this.debitNotesField;
}
set {
this.debitNotesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal CreditNotes {
get {
return this.creditNotesField;
}
set {
this.creditNotesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal CashReceipts {
get {
return this.cashReceiptsField;
}
set {
this.cashReceiptsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal OtherPositive {
get {
return this.otherPositiveField;
}
set {
this.otherPositiveField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal OtherNegative {
get {
return this.otherNegativeField;
}
set {
this.otherNegativeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal ClosingBalance {
get {
return this.closingBalanceField;
}
set {
this.closingBalanceField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class FileSummaryDebtor {
private object[] itemsField;
private string debtorIdField;
private string debtorNameField;
private string excludedDebtorField;
private decimal creditLimitField;
private string debtorStatusField;
private string tradingTermsField;
private uint overduePeriodField;
private string headOfficeCodeField;
private string headOfficeNameField;
private string debtorCountryField;
private string aBNField;
private string aRBNField;
private string aCNField;
private string legalNameField;
private string mainTradingNameField;
private string otherTradingNameField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("DebtorContact", typeof(FileSummaryDebtorDebtorContact))]
public object[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DebtorId {
get {
return this.debtorIdField;
}
set {
this.debtorIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DebtorName {
get {
return this.debtorNameField;
}
set {
this.debtorNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ExcludedDebtor {
get {
return this.excludedDebtorField;
}
set {
this.excludedDebtorField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal CreditLimit {
get {
return this.creditLimitField;
}
set {
this.creditLimitField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DebtorStatus {
get {
return this.debtorStatusField;
}
set {
this.debtorStatusField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string TradingTerms {
get {
return this.tradingTermsField;
}
set {
this.tradingTermsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public uint OverduePeriod {
get {
return this.overduePeriodField;
}
set {
this.overduePeriodField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string HeadOfficeCode {
get {
return this.headOfficeCodeField;
}
set {
this.headOfficeCodeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string HeadOfficeName {
get {
return this.headOfficeNameField;
}
set {
this.headOfficeNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DebtorCountry {
get {
return this.debtorCountryField;
}
set {
this.debtorCountryField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ABN {
get {
return this.aBNField;
}
set {
this.aBNField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ARBN {
get {
return this.aRBNField;
}
set {
this.aRBNField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ACN {
get {
return this.aCNField;
}
set {
this.aCNField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string LegalName {
get {
return this.legalNameField;
}
set {
this.legalNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string MainTradingName {
get {
return this.mainTradingNameField;
}
set {
this.mainTradingNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string OtherTradingName {
get {
return this.otherTradingNameField;
}
set {
this.otherTradingNameField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class FileSummaryDebtorDebtorContact {
private string surnameField;
private string firstNameField;
private string otherNamesField;
private string phoneField;
private string mobileField;
private string faxField;
private string emailField;
private string salutationField;
private string jobTitleField;
private string contactAddressField;
private string contactSuburbField;
private string contactCountryField;
private string contactStateField;
private string contactPostcodeField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Surname {
get {
return this.surnameField;
}
set {
this.surnameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string FirstName {
get {
return this.firstNameField;
}
set {
this.firstNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string OtherNames {
get {
return this.otherNamesField;
}
set {
this.otherNamesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Phone {
get {
return this.phoneField;
}
set {
this.phoneField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Mobile {
get {
return this.mobileField;
}
set {
this.mobileField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Fax {
get {
return this.faxField;
}
set {
this.faxField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Email {
get {
return this.emailField;
}
set {
this.emailField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Salutation {
get {
return this.salutationField;
}
set {
this.salutationField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string JobTitle {
get {
return this.jobTitleField;
}
set {
this.jobTitleField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ContactAddress {
get {
return this.contactAddressField;
}
set {
this.contactAddressField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ContactSuburb {
get {
return this.contactSuburbField;
}
set {
this.contactSuburbField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ContactCountry {
get {
return this.contactCountryField;
}
set {
this.contactCountryField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ContactState {
get {
return this.contactStateField;
}
set {
this.contactStateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ContactPostcode {
get {
return this.contactPostcodeField;
}
set {
this.contactPostcodeField = value;
}
}
}
using System;
namespace CoinsAssetWatchXMLGen
{
class Program
{
static void Main(string[] args)
{
FileSummary fileSummary = new FileSummary();
fileSummary.FileDate = DateTime.Today;
FileSummaryDebtor debtor = new FileSummaryDebtor;
debtor.DebtorId = "11";
debtor.DebtorName = "fred";
debtor.DebtorStatus = "active";
debtor.ABN = "ABC1234567";
fileSummary.Debtor[1] = debtor;
//how do I associate this following with a debtor for XML??
FileSummaryDebtorDebtorContact contact = new FileSummaryDebtorDebtorContact();
}
}
}
答案 0 :(得分:0)
我采用的方法是使用xsd.exe / d创建数据集类。 创建数据集类后
我最初按照以下方式填充数据表,以便更好地了解数据集结构:
NewDataSet newDataSet = new NewDataSet();
newDataSet.ReadXml("FileSummary.xml");