好吧,這些命名空間再一次超出了我的頭。XML到LINQ反序列化爲XML文檔中的對象
我想要一個長的XML文檔並將其反序列化爲實體對象列表。這種情況下的物體就像平坦的POJO。
的XML看起來像:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<QueryResponse xmlns="http://markets.midwestiso.org/dart/xml">
<DayAheadLMP day="2011-02-25">
<PricingNode location="AEC">
<PricingNodeHourly hour="1">
<LMP>23.1</LMP>
<MCC>-0.44</MCC>
<MLC>-0.49</MLC>
<RegMCP>0</RegMCP>
<SpinMCP>0</SpinMCP>
<SuppMCP>0</SuppMCP>
</PricingNodeHourly>
等等等等。
我已經得到了儘可能:
var repsonseXML = XDocument.Parse(CallMUI(requestXml, muiUrl));
它返回我的XML作爲字符串並將其解析到XDocument對象
我想要的列表對象如下:
/// <summary>
/// There are no comments for MISO.IR.IntegrationModel.LMP_DayAhead in the schema.
/// </summary>
/// <KeyProperties>
/// Location
/// Interval
/// SyncId
/// </KeyProperties>
[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="MISO.IR.IntegrationModel", Name="LMP_DayAhead")]
[global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]
[global::System.Serializable()]
public partial class LMP_DayAhead : global::System.Data.Objects.DataClasses.EntityObject
{
/// <summary>
/// Create a new LMP_DayAhead object.
/// </summary>
/// <param name="location">Initial value of Location.</param>
/// <param name="interval">Initial value of Interval.</param>
/// <param name="lMP">Initial value of LMP.</param>
/// <param name="mLC">Initial value of MLC.</param>
/// <param name="mCC">Initial value of MCC.</param>
/// <param name="syncId">Initial value of SyncId.</param>
[global::System.CodeDom.Compiler.GeneratedCode("System.Data.Entity.Design.EntityClassGenerator", "4.0.0.0")]
public static LMP_DayAhead CreateLMP_DayAhead(string location, global::System.DateTime interval, decimal lMP, decimal mLC, decimal mCC, int syncId)
{
LMP_DayAhead lMP_DayAhead = new LMP_DayAhead();
lMP_DayAhead.Location = location;
lMP_DayAhead.Interval = interval;
lMP_DayAhead.LMP = lMP;
lMP_DayAhead.MLC = mLC;
lMP_DayAhead.MCC = mCC;
lMP_DayAhead.SyncId = syncId;
return lMP_DayAhead;
}
如何使用所有這些名稱空間完成它?
你想在你的XML generete類的代碼庫? – Stecya 2011-02-25 18:19:27
是的,我想XML基本上變成了一個對象列表。 – 2011-02-25 18:23:02
然後看看這個問題(也許它是類似的)http://stackoverflow.com/questions/5118450/generate-poco-objects-from-xml-file/5118502#5118502 – Stecya 2011-02-25 18:26:37