更新我有一个相当大的 XML 文档,其中包含超过 20,000 个对象。它突然抛出 System.XML.XMLException: Root Element is Missing。
这是我的代码块:
public async Task<int> readDatabase()
{
IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication();
List<card> temp= new List<card>();
XmlSerializer s = new XmlSerializer(typeof(List<card>), new XmlRootAttribute("card"));
using (TextReader reader = new StreamReader(myFile.OpenFile("cards.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
cardList = (List<card>)s.Deserialize(reader);
}
return 1;
}
我的卡片对象在 XML 中的示例
<?xml version="1.0" encoding="UTF-8"?>
<mtg_carddatabase>
<bdd_date><![CDATA[5/1/2013]]></bdd_date>
<bdd_version><![CDATA[1.00]]></bdd_version>
<bdd_name>Magic the Gathering® Card Database</bdd_name>
<bdd_editor>Wizards of the Coast LLC</bdd_editor>
<sets>
<set>
<name><![CDATA[15th Anniversary]]></name>
<code><![CDATA[15A]]></code>
<code_magiccards><![CDATA[15ANN]]></code_magiccards>
<date><![CDATA[00/0000]]></date>
<is_promo><![CDATA[True]]></is_promo>
</set>
</sets>
<cards>
<card>
<id><![CDATA[3064]]></id>
<name><![CDATA[Urza's Engine]]></name>
<set><![CDATA[AL]]></set>
<type><![CDATA[Artifact Creature — Juggernaut]]></type>
<rarity><![CDATA[U]]></rarity>
<manacost><![CDATA[{5}]]></manacost>
<converted_manacost><![CDATA[5]]></converted_manacost>
<power><![CDATA[1]]></power>
<toughness><![CDATA[5]]></toughness>
<loyalty></loyalty>
<ability><![CDATA[Trample£{3}: Urza's Engine gains banding until end of turn. #_(Any
creatures with banding, and up to one without, can attack in a band. Bands are blocked as a
group. If any creatures with banding you control are blocking or being blocked by a
creature, you divide that creature's combat damage, not its controller, among any of the
creatures it's being blocked by or is blocking.)_#£{3}: Attacking creatures banded with
Urza's Engine gain trample until end of turn.]]></ability>
<flavor><![CDATA[#_"Humans and machines working together can be fearsome indeed"Arcum
Dagsson_#]]></flavor>
<variation></variation>
<artist><![CDATA[Greg Simanson]]></artist>
<number><![CDATA[180]]></number>
<rating><![CDATA[2.449]]></rating>
<ruling><![CDATA[£10/1/2008 : If a creature with banding attacks, it can team up with any
number of other attacking creatures with banding (and up to one nonbanding creature) and
attack as a unit called a "band." The band can be blocked by any creature that could block a
single creature in the band. Blocking any creature in a band blocks the entire band. If a
creature with banding is blocked, the attacking player chooses how the blockers' damage is
assigned. £10/1/2008 : A maximum of one nonbanding creature can join an attacking band no
matter how many creatures with banding are in it. £10/1/2008 : Creatures in the same band
must all attack the same player or planeswalker. £10/1/2009 : If a creature in combat has
banding, its controller assigns damage for creatures blocking or blocked by it. That player
can ignore the damage assignment order when making this assignment.]]></ruling>
<color><![CDATA[A]]></color>
<generated_mana></generated_mana>
<pricing_low><![CDATA[0,08]]></pricing_low>
<pricing_mid><![CDATA[0,25]]></pricing_mid>
<pricing_high><![CDATA[1,01]]></pricing_high>
<back_id></back_id>
<watermark></watermark>
<name_CN><![CDATA[]]></name_CN>
<name_TW><![CDATA[]]></name_TW>
<name_FR><![CDATA[Locomotive d'Urza]]></name_FR>
<name_DE><![CDATA[Urzas Maschine]]></name_DE>
<name_IT><![CDATA[Motrice di Urza]]></name_IT>
<name_JP><![CDATA[]]></name_JP>
<name_PT><![CDATA[Engenho de Urza]]></name_PT>
<name_RU><![CDATA[]]></name_RU>
<name_ES><![CDATA[Ingenio de Urza]]></name_ES>
<name_KO><![CDATA[]]></name_KO>
<legality_Block><![CDATA[b]]></legality_Block>
<legality_Standard><![CDATA[b]]></legality_Standard>
<legality_Extended><![CDATA[b]]></legality_Extended>
<legality_Modern><![CDATA[b]]></legality_Modern>
<legality_Legacy><![CDATA[v]]></legality_Legacy>
<legality_Vintage><![CDATA[v]]></legality_Vintage>
<legality_Highlander><![CDATA[v]]></legality_Highlander>
<legality_French_Commander><![CDATA[v]]></legality_French_Commander>
<legality_Commander><![CDATA[v]]></legality_Commander>
<legality_Peasant><![CDATA[u]]></legality_Peasant>
<legality_Pauper><![CDATA[b]]></legality_Pauper>
</card>
</cards>
</mtg_carddatabase>
这个问题看起来像我的解串器,但直到上周它都运行良好。:(