0
枚舉的XML文件創建一個類我試圖使用xsd.exe爲我的xml創建一個類,它似乎工作,但我可以枚舉該類。我甚至試圖使用Xsd2Code,但會導致這個錯誤「有一個錯誤反映類型'MySQlXML.XBMC'。」當我試圖通過列表枚舉 時。請讓我知道,如果你有任何想法,我可以如何讓枚舉工作。從可通過
這是我的XML
<?xml version="1.0" encoding="utf-8"?>
<XBMC>
<Show>
<IdShow>1</IdShow>
<TheTvDbId>248741</TheTvDbId>
<ShowName>2 Broke Girls</ShowName>
<Seasons>
<Season>
<Number>1</Number>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season1\</Path>
</Season>
<Season>
<Number>3</Number>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season 03\</Path>
</Season>
</Seasons>
</Show>
<Show>
<IdShow>164</IdShow>
<TheTvDbId>75682</TheTvDbId>
<ShowName>Bones</ShowName>
<Seasons>
<Season>
<Number>1</Number>
<Path>\\10.0.0.3\TV2\Bones\Season 01\</Path>
</Season>
</Seasons>
</Show>
</XBMC>
這是怎麼序列化數據,但是當我嘗試foreach (XBMCShow show in test)
我得到foreach語句,因爲「MySQlXML.XBMC」確實不能在類型爲「MySQlXML.XBMC」變量操作不包含關於 '的GetEnumerator'
TextReader reader = new StreamReader(_XMLFile);
XmlSerializer serializer = new XmlSerializer(typeof(XBMC));
test = (XBMC)serializer.Deserialize(reader);
reader.Close();
這是類XSD.EXE生成的公共定義。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace MySQlXML
{
/// <remarks/>
public partial class XBMC
{
private XBMCShow[] showField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Show")]
public XBMCShow[] Show
{
get
{
return this.showField;
}
set
{
this.showField = value;
}
}
}
/// <remarks/>
public partial class XBMCShow
{
public ushort idShowField;
public string theTvDbIdField;
public string showNameField;
private XBMCShowSeason[] seasonsField;
/// <remarks/>
public ushort IdShow
{
get
{
return this.idShowField;
}
set
{
this.idShowField = value;
}
}
/// <remarks/>
public string TheTvDbId
{
get
{
return this.theTvDbIdField;
}
set
{
this.theTvDbIdField = value;
}
}
/// <remarks/>
public string ShowName
{
get
{
return this.showNameField;
}
set
{
this.showNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Season", IsNullable = false)]
public XBMCShowSeason[] Seasons
{
get
{
return this.seasonsField;
}
set
{
this.seasonsField = value;
}
}
}
/// <remarks/>
public partial class XBMCShowSeason
{
private byte numberField;
private string pathField;
/// <remarks/>
public byte Number
{
get
{
return this.numberField;
}
set
{
this.numberField = value;
}
}
/// <remarks/>
public string Path
{
get
{
return this.pathField;
}
set
{
this.pathField = value;
}
}
}
}
確定這工作,謝謝,我怎麼會選擇從陣列例如 – justinf
看到「識骨尋蹤」節目最後一件事如果如果作品:) – inquisitive
很酷,如果我想要做循環雖然整個數組通常可以使用數組索引但是這不是一個選項聽到想要這樣的'test.Show [] .ShowName ==「Bones」' – justinf