如何从xml输出

时间:2017-09-06 15:54:47

标签: c# xml serialization

我有一个服务,它接收行数据文本并将数据解析为XML格式。该服务正在运行,但是我得到的输出" anyType xsi:type =" R0001"而不仅仅是节点的R0001。我已经尝试了一些我在StackOverflow上找到的建议,但它们似乎都不适用于我的代码。有人会有什么建议吗?请参阅提供的示例:

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Client_Data_Parser
{
    public class Records
    {
        public List<Record> WCErecords { get; set; }
    }

    [XmlInclude(typeof(R0001))]
    [XmlInclude(typeof(R0002))]
    [XmlInclude(typeof(R0003))]
    [XmlInclude(typeof(R0004))]
    [XmlInclude(typeof(R0005))]
    [XmlInclude(typeof(R0006))]
    [XmlInclude(typeof(R0007))]
    [Serializable()]
    public class Record
    {
        public List<object> DataSet { get; set; }
    }
    [Serializable()]
    public class R0001
    {
        public string RecKey { get; set; }
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string FormRelationCode { get; set; }
        public string RecipientCode { get; set; }
        public string ClaimType { get; set; }
        public string PullCode { get; set; }
        public string SendToName { get; set; }
        public string SentToAddress1 { get; set; }
        public string SendToAddress2 { get; set; }
        public string SendToCity { get; set; }
        public string SendToState { get; set; }
        public string SendToZip { get; set; }
        public string ForeignCountry { get; set; }
        public string EmailAddress { get; set; }
        public string FaxNumber { get; set; }
        public string MailID { get; set; }
    }

    [Serializable()]
    public class R0002
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string InsuredSeqNum { get; set; }
        public string RunNumSeq { get; set; }
        public string DraftCode { get; set; }
        public string PreauthorizationFlag { get; set; }
        public string MemberName { get; set; }
        public string MemberSSN { get; set; }
        public string ClaimantAddress1 { get; set; }
        public string ClaimantAddress2 { get; set; }
        public string ClaimantAddress3 { get; set; }
        public string ClaimantCountry { get; set; }
        public string ClaimantName { get; set; }
        public string ClaimantDOB { get; set; }
        public string ClaimantsNumber { get; set; }
        public string ClaimantsAcctNum { get; set; }
        public string ClaimantsRelation { get; set; }
        public string ClaimNumber { get; set; }
        public string ExaminerCode { get; set; }
        public string ExaminerName { get; set; }
        public string ReceivedDate { get; set; }
        public string EntryDate { get; set; }
        public string ReleasedDate { get; set; }
        public string DISDailyBenefitRate { get; set; }
        public string DISWeeklyBenefitRate { get; set; }
        public string DISType { get; set; }
        public string DISBenefitDays { get; set; }
        public string DISBenefitWeeks { get; set; }
        public string DISInjuryDate { get; set; }
        public string DISBackToWorkDate { get; set; }
        public string DISLastWorkDate { get; set; }
        public string DISLastBenefitDate { get; set; }
        public string DIS_YTDTotalAmount { get; set; }
        public string ProviderTIN { get; set; }
        public string BillingProviderName { get; set; }
        public string ServiceProviderName { get; set; }
        public string ProviderAddress1 { get; set; }
        public string ProviderAddress2 { get; set; }
        public string ProviderAddress3 { get; set; }
        public string ProviderCountry { get; set; }
        public string FundCode { get; set; }
        public string FundName { get; set; }
        public string FundAddress1 { get; set; }
        public string FundAddress2 { get; set; }
        public string FundAddress3 { get; set; }
        public string GroupCode { get; set; }
        public string GroupName { get; set; }
        public string GroupAddress1 { get; set; }
        public string GroupAddress2 { get; set; }
        public string GroupAddress3 { get; set; }
        public string Subgroup { get; set; }
        public string SubgroupName { get; set; }
        public string Local { get; set; }
        public string BenefitPlanCode { get; set; }
        public string BenefitPlanDescription { get; set; }
        public string CoverageCode { get; set; }
        public string CoverageDescription { get; set; }
        public string AgentCode { get; set; }
        public string AgentName { get; set; }
        public string EmployerCode { get; set; }
        public string EmployerName { get; set; }
        public string ClaimAssignment { get; set; }
        public string PrintDate { get; set; }    
    }

    [Serializable()]
    public class R0003
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string InsuredSeqNum { get; set; }
        public string LineItemNum { get; set; }
        public string FromDate { get; set; }
        public string ThruDate { get; set; }
        public string ProcedureCode { get; set; }
        public string Modifier { get; set; }
        public string DiagnosisCode1 { get; set; }
        public string DiagnosisCode2 { get; set; }
        public string DiagnosisCode3 { get; set; }
        public string DiagnosisCode4 { get; set; }
        public string ToothSurface1 { get; set; }
        public string ToothSurface2 { get; set; }
        public string ToothSurface3 { get; set; }
        public string Quantity { get; set; }
        public string ServiceDescription { get; set; }
        public string Billed { get; set; }
        public string TotalLineItemIneligAmt { get; set; }
        public string PayType1 { get; set; }
        public string PayType2 { get; set; }
        public string PayType3 { get; set; }
        public string DiscountAmount { get; set; }
        public string CoveredAmount { get; set; }
        public string PlanAllowedAmount1 { get; set; }
        public string PlanAllowedAmount2 { get; set; }
        public string PlanAllowedAmount3 { get; set; }
        public string DeductibleType1 { get; set; }
        public string DeductibleType2 { get; set; }
        public string DeductibleType3 { get; set; }
        public string Deductible1 { get; set; }
        public string Deductible2 { get; set; }
        public string Deductible3 { get; set; }
        public string NetAllowed1 { get; set; }
        public string NetAllowed2 { get; set; }
        public string NetAllowed3 { get; set; }
        public string CoinsuranceRate1 { get; set; }
        public string CoinsuranceRate2 { get; set; }
        public string CoinsuranceRate3 { get; set; }
        public string GrossCovered1 { get; set; }
        public string GrossCovered2 { get; set; }
        public string GrossCovered3 { get; set; }
        public string COBAdjustment1 { get; set; }
        public string COBAdjustment2 { get; set; }
        public string COBAdjustment3 { get; set; }
        public string NetCovered1 { get; set; }
        public string NetCovered2 { get; set; }
        public string NetCovered3 { get; set; }
        public string NetCoveredDiscount { get; set; }
        public string LineItemPaid { get; set; }
        public string PatientLiabilityAmount { get; set; }
        public string ProviderLiabilityAmount { get; set; }
        public string FSALiabilityAmount { get; set; }
        public string PrepaidInsured { get; set; }
        public string PrepaidOtherInsurance { get; set; }
        public string PrepaidMedicare { get; set; }
        public string PPOcode { get; set; }
        public string PPOdescription { get; set; }
        public string DISGrossBenefit { get; set; }
        public string DISWithholdingType1 { get; set; }
        public string DISWithholdingDescription1 { get; set; }
        public string DISWithholdingAmount1 { get; set; }
        public string DISWithholdingType2 { get; set; }
        public string DISWithholdingDescription2 { get; set; }
        public string DISWithholdingAmount2 { get; set; }
        public string DISWithholdingType3 { get; set; }
        public string DISWithholdingDescription3 { get; set; }
        public string DISWithholdingAmount3 { get; set; }
        public string DISWithholdingType4 { get; set; }
        public string DISWithholdingDescription4 { get; set; }
        public string DISWithholdingAmount4 { get; set; }
        public string DISWithholdingType5 { get; set; }
        public string DISWithholdingDescription5 { get; set; }
        public string DISWithholdingAmount5 { get; set; }
        public string DISWithholdingType6 { get; set; }
        public string DISWithholdingDescription6 { get; set; }
        public string DISWithholdingAmount6 { get; set; }
        public string DISWithholdingType7 { get; set; }
        public string DISWithholdingDescription7 { get; set; }
        public string DISWithholdingAmount7 { get; set; }
        public string DISWithholdingType8 { get; set; }
        public string DISWithholdingDescription8 { get; set; }
        public string DISWithholdingAmount8 { get; set; }
        public string DISWithholdingType9 { get; set; }
        public string DISWithholdingDescription9 { get; set; }
        public string DISWithholdingAmount9 { get; set; }
        public string DISWithholdingType10 { get; set; }
        public string DISWithholdingDescription10 { get; set; }
        public string DISWithholdingAmount10 { get; set; }
        public string DISNetBenefitDue { get; set; }
        public string DISTotalPayable { get; set; }
        public string LineItemRemarkCode1 { get; set; }
        public string LineItemRemarkCode2 { get; set; }
        public string LineItemRemarkCode3 { get; set; }
        public string LineItemRemarkCode4 { get; set; }
        public string LineItemRemarkCode5 { get; set; }
        public string LineItemRemarkCode6 { get; set; }
        public string LineItemRemarkCode7 { get; set; }
        public string LineItemRemarkCode8 { get; set; }
        public string LineItemRemarkCode9 { get; set; }
        public string LineItemRemarkCode10 { get; set; }
        public string AmountNotCoveredByInsurance { get; set; }
    }

    [Serializable()]
    public class R0004
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string InsuredSeqNum { get; set; }
        public string TotalBilled { get; set; }
        public string TotalLineItemIneligAmt { get; set; }
        public string TotalDiscountAmount { get; set; }
        public string TotalCoveredAmount { get; set; }
        public string TotalPlanAllowedAmount { get; set; }
        public string TotalDeductible { get; set; }
        public string TotalNetAllowed { get; set; }
        public string TotalGrossCovered { get; set; }
        public string TotalCOBadjustment { get; set; }
        public string TotalNetCovered { get; set; }
        public string TotalNetCoveredDiscount { get; set; }
        public string TotalPatientLiabilityAmt { get; set; }
        public string TotalProviderLiability { get; set; }
        public string TotalFSAliabilityAmount { get; set; }
        public string TotalPrepaidInsured { get; set; }
        public string TotalPrepaidOther { get; set; }
        public string TotalPrepaidMedicare { get; set; }
        public string TotalPriorPmtAdjustment { get; set; }
        public string TotalPaidPlan1 { get; set; }
        public string TotalPaidPlan2 { get; set; }
        public string TotalPaid { get; set; }
        public string DISGrossBenefit { get; set; }
        public string DISWithholdingType1 { get; set; }
        public string DISWithholdingAmount1 { get; set; }
        public string DISWithholdingType2 { get; set; }
        public string DISWithholdingAmount2 { get; set; }
        public string DISWithholdingType3 { get; set; }
        public string DISWithholdingAmount3 { get; set; }
        public string DISWithholdingType4 { get; set; }
        public string DISWithholdingAmount4 { get; set; }
        public string DISWithholdingType5 { get; set; }
        public string DISWithholdingAmount5 { get; set; }
        public string DISWithholdingType6 { get; set; }
        public string DISWithholdingAmount6 { get; set; }
        public string DISWithholdingType7 { get; set; }
        public string DISWithholdingAmount7 { get; set; }
        public string DISWithholdingType8 { get; set; }
        public string DISWithholdingAmount8 { get; set; }
        public string DISWithholdingType9 { get; set; }
        public string DISWithholdingAmount9 { get; set; }
        public string DISWithholdingType10 { get; set; }
        public string DISWithholdingAmount10 { get; set; }
        public string DISNetBenefitDue { get; set; }
        public string DISTotalPayable { get; set; }
        public string LineItemRemarkCode1 { get; set; }
        public string LineItemRemarkCode2 { get; set; }
        public string LineItemRemarkCode3 { get; set; }
        public string LineItemRemarkCode4 { get; set; }
        public string LineItemRemarkCode5 { get; set; }
        public string LineItemRemarkCode6 { get; set; }
        public string LineItemRemarkCode7 { get; set; }
        public string LineItemRemarkCode8 { get; set; }
        public string LineItemRemarkCode9 { get; set; }
        public string LineItemRemarkCode10 { get; set; }
        public string DISContinuationFormFlag { get; set; }
        public string AmountNotCoveredByInsurance { get; set; }
    }

    [Serializable()]
    public class R0005
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string InsuredSeqNum { get; set; }
        public string ClaimNumber { get; set; }
        public string LineItemNumber { get; set; }
        public string CommentRemarkCode { get; set; }
        public string Comment { get; set; }
    }

    [Serializable()]
    public class R0006
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string InsuredSeqNum { get; set; }
        public string PayeeName { get; set; }
        public string CheckNumber { get; set; }
        public string CheckAmount { get; set; }
        public string CheckDate { get; set; }
    }

    [Serializable()]
    public class R0007
    {
        public string RecordType { get; set; }
        public string ABFKey { get; set; }
        public string CheckNumber { get; set; }
        public string CheckAmount { get; set; }
        public string CheckDate { get; set; }
        public string MicrCheckNumber { get; set; }
        public string MicrOnusNumber { get; set; }
        public string MicrTransitNumber { get; set; }
        public string BankName { get; set; }
        public string BankAddress1 { get; set; }
        public string BankAddress2 { get; set; }
        public string BankCityStateZip { get; set; }
        public string BankCountry { get; set; }
        public string PayeeTIN { get; set; }
        public string PayeeName { get; set; }
        public string PayeeAddress1 { get; set; }
        public string PayeeAddress2 { get; set; }
        public string PayeeCityStateZip { get; set; }
        public string PayeeCountry { get; set; }
        public string CheckAmountText { get; set; }
        public string FractionalRoutingNumber { get; set; }
    }
}

我正在创建一个带有类&#34;记录&#34;的对象列表。与每个对应的记录类型。每个&#34;记录&#34;被添加到&#34;记录&#34;输出的类列表我的XML看起来像:

<!-- language: lang-xml -->
<?xml version="1.0"?>
<Records xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <WCErecords>
    <Record>
      <DataSet>
        <anyType xsi:type="R0001">
          <RecKey>0000000201612191200000304</RecKey>
          <RecordType>0001</RecordType>
          <ABFKey>0000000201612191200000304</ABFKey>
          <FormRelationCode>001</FormRelationCode>
          <RecipientCode>P </RecipientCode>
          <ClaimType>MED</ClaimType>
          <PullCode>  </PullCode>
          <SendToName>SETH L IVINS MD</SendToName>
          <SentToAddress1>PO BOX 71256</SentToAddress1>
          <SendToAddress2 />
          <SendToCity>PHILA</SendToCity>
          <SendToState>PA</SendToState>
          <SendToZip>19176</SendToZip>
          <ForeignCountry />
          <EmailAddress />
          <FaxNumber>          </FaxNumber>
          <MailID>                              </MailID>
        </anyType>
       </DataSet>
    </Record>
  </WCErecords>
</Records>

如果需要任何其他信息或代码,请告诉我。上面的XML只是一个包含一种数据类型的示例,以免压倒包含大量文本的页面。所以我要找的是删除&#34; anyType xsi:type&#34;并且只需阅读&#34; R0001&#34;。

1 个答案:

答案 0 :(得分:3)

为集合中的每种可能类型添加属性XmlArrayItem,如:

[XmlArrayItem(typeof(R0001), ElementName = "R0001")]
[XmlArrayItem(typeof(R0002), ElementName = "R0002")]
[XmlArrayItem(typeof(R0003), ElementName = "R0003")]
public List<object> DataSet { get; set; }