以上<?xml version="1.0" encoding="utf-8" standalone="yes"?> <DPDocument> <TradingPartnerDirectory> <Sender> <TradingPartner ParticipantType="Distributor"> <CompanyID>200408144</CompanyID> <CompanyName>Union Gas Ltd</CompanyName> </TradingPartner> </Sender> <Recipient> <TradingPartner ParticipantType="Retailer"> <CompanyID>DUNS24653</CompanyID> <CompanyName>Local Authority Services Limited</CompanyName> </TradingPartner> </Recipient> </TradingPartnerDirectory> <ContractInformation> <ContractID>SA1854</ContractID> <ContractName>GASAMO #1 EDA-ABC</ContractName> <Amendment>24</Amendment> <FirstDeliveryDate>11/1/2011</FirstDeliveryDate> <EffectiveDate>11/1/2011</EffectiveDate> <DeliveryArea>EDA</DeliveryArea> <TotalDCQ>546</TotalDCQ> <EnergyFactor>37.51</EnergyFactor> <EndUseLocationInformation> <AccountNumber>10109251120297</AccountNumber> <AccountName>TOWN OF DESERONTO</AccountName> <RateClass>01</RateClass> <ServiceClass>C</ServiceClass> <ForecastInformation> <BillingMonth>JAN</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>1116.0040</Consumption> <WeatherFactor>1.045723</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>FEB</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>1269.7390</Consumption> <WeatherFactor>0.937073</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>MAR</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>2064.0370</Consumption> <WeatherFactor>1.015836</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>APR</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>82.5610</Consumption> <WeatherFactor>0.982911</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>MAY</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>546.6140</Consumption> <WeatherFactor>0.972752</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>JUN</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>128.1130</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>JUL</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>5.6940</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>AUG</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>0</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>SEP</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>0</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>OCT</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>2.8470</Consumption> <WeatherFactor>0.993534</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>NOV</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>290.3890</Consumption> <WeatherFactor>1.0585</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>DEC</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>686.1140</Consumption> <WeatherFactor>0.938379</WeatherFactor> </ForecastInformation> </EndUseLocationInformation> <EndUseLocationInformation> <AccountNumber>10110651120442</AccountNumber> <AccountName>COMMUNITY CENTRE</AccountName> <RateClass>01</RateClass> <ServiceClass>C</ServiceClass> <ForecastInformation> <BillingMonth>JAN</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>4327.3610</Consumption> <WeatherFactor>1.045723</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>FEB</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>4811.3420</Consumption> <WeatherFactor>0.937073</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>MAR</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>5924.4990</Consumption> <WeatherFactor>1.015836</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>APR</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>4971.9730</Consumption> <WeatherFactor>0.982911</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>MAY</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>2302.5290</Consumption> <WeatherFactor>0.972752</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>JUN</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>761.1410</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>JUL</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>350.3160</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>AUG</BillingMonth> <BillingYear>2011</BillingYear> <Consumption>267.5140</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>SEP</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>42.7050</Consumption> <WeatherFactor>1</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>OCT</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>416.8490</Consumption> <WeatherFactor>0.993534</WeatherFactor> <WeatherFactor>0.993534</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>NOV</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>1389.3110</Consumption> <WeatherFactor>1.0585</WeatherFactor> </ForecastInformation> <ForecastInformation> <BillingMonth>DEC</BillingMonth> <BillingYear>2010</BillingYear> <Consumption>1641.4940</Consumption> <WeatherFactor>0.938379</WeatherFactor> </ForecastInformation> </EndUseLocationInformation> </DPDocument>
是我的XML代碼..我無法將其轉換成下面的C#類是我爲XMLXML到C#不能轉換
public class DPDocument
{
public TradingPartnerDirectory tradingpartnerdirectory
{
get;
set;
}
public ContractInformation contractInformation
{
get;
set;
}
public DPDocument()
{
tradingpartnerdirectory = new TradingPartnerDirectory();
contractInformation = new ContractInformation();
}
}
public class TradingPartnerDirectory
{
public Sender sender
{
get;
set;
}
public Recipient recipient
{
get;
set;
}
public TradingPartnerDirectory()
{
sender = new Sender();
recipient = new Recipient();
}
}
public class Sender
{
public TradingPartner tradingPartner
{
get;
set;
}
public Sender()
{
tradingPartner = new TradingPartner();
}
}
public class Recipient
{
public TradingPartner tradingPartner
{
get;
set;
}
public Recipient()
{
tradingPartner = new TradingPartner();
}
}
public class TradingPartner
{
[XmlAttribute("ParticipantType")]
public string ParticipantType
{
get;
set;
}
public long CompanyID
{
get;
set;
}
public string CompanyName
{
get;
set;
}
}
public class ContractInformation
{
public string ContractID
{
get;
set;
}
public string ContractName
{
get;
set;
}
public int Amendment
{
get;
set;
}
public DateTime FirstDeliveryDate
{
get;
set;
}
public DateTime EffectiveDate
{
get;
set;
}
public string DeliveryArea
{
get;
set;
}
public int TotalDCQ
{
get;
set;
}
public decimal EnergyFactor
{
get;
set;
}
public List<EndUseLocationInformation> child
{
get;
set;
}
public ContractInformation()
{
child = new List<EndUseLocationInformation>();
}
}
public class EndUseLocationInformation
{
public long AccountNumber
{
get;
set;
}
public string AccountName
{
get;
set;
}
public int RateClass
{
get;
set;
}
public string ServiceClass
{
get;
set;
}
public List<ForecastInformation> childchild
{
get;
set;
}
public EndUseLocationInformation()
{
childchild = new List<ForecastInformation>();
}
}
public class ForecastInformation
{
public string BillingMonth
{
get;
set;
}
public int BillingYear
{
get;
set;
}
public decimal Consumption
{
get;
set;
}
public decimal WeatherFactor
{
get;
set;
}
public ForecastInformation()
{
}
}
創建的C#類
我不能夠在一次單一鏡頭中將其轉換爲c#DPDocument對象,我嘗試了所有方法,但是我沒有實現這一目標。 最後我遇到了一個最糟糕的解決方案,比如通過單個節點列表並最終處理該列表,該方法對我有用。但我需要一個優雅的解決方案來解決我的問題。 預先感謝:)
是的。 ''標籤沒有關閉。 –
Strelok
2011-12-19 05:53:32
不是唯一的;)其實還有更多。因此沒有辦法通過標準的XML機制來處理這個文檔。 – TomTom 2011-12-19 05:55:42
如果你發現任何標籤沒有關閉,對不起,這是我的錯誤,但我的XML文件看起來只有這樣,它格式良好。如果你有任何想法轉換一個PLZ給我寶貴的解決方案給我,謝謝:) – Ramakrishna 2011-12-19 07:13:46