Xml - 序列化 - 子节点问题

时间:2014-01-15 13:52:39

标签: xml c#-4.0

我正在尝试将此Xml文件序列化到卡类

   public class card
    {
        public string id;
        public string name;
        public string Type;
        ...
    }


<card id="5cf0be26-ce65-405f-9c4a-312f31bceedb" name="Warlord">
        <property name="Type" value="Mage" />
        <property name="Stats" value="Spellbook=120,Life=36,Armor=0,Channeling=9,War=1,Earth=1,Arcane=3" />
        <property name="Traits" value="Melee +1" />
        <property name="Text" value="Training: Trained in the War and Earth schools of Magic. Arcane spells cost triple during spellbook construction. \n Veterans: Whenever a friendly non-Mage creature melee attacks and destroys an enemy creature, place a veteran badge token on that creature (maximum of one token per creature). That creature gains Melee +1 and Armor +1. \n Battle Orders: Once per round, the Warlord may pay 1 mana and cast one of the following quick command spells. The chosen spell affects all friendly soldiers in his zone at the time it is cast and the effect lasts until the end of the round. To Battle! - Gain charge +1 trait; Release Volley! - Gain Ranged +1 trait; On Guard! - Gain Melee +1 and Armor +1 while guarding. \n Battle Skill: Warlord has Melee +1 trait. \n \n Basic Melee Attack: [Quick][Melee][Dice=3]" />
    </card>

    <card id="37ba1909-7eed-4b8a-8224-429f22674128" name="Arc Lightning">
        <property name="Type" value="Attack" />
        <property name="Subtype" value="Lightning" />
        <property name="School" value="Air" />
        <property name="Action" value="Q" />
        <property name="Cost" value="5" />
        <property name="Level" value="1" />
        <property name="Traits" value="" />
        <property name="Range" value="0-1" />
        <property name="Target" value="Creature or Conjuration" />
        <property name="Text" value="[Ranged] Lightning][Dice=3][d12][7-8 = Daze; 9+ = Stun][Ethereal,Unavoidable]" />
        <property name="CardID" value="FWA01" />
    </card>

正如你可以看到两张卡之间的属性变化数量及其问题。

第一个属性,Id和名称有效,但我没有得到所有其他

我尝试过:

XDocument xdoc1 = XDocument.Load(path);

   var zz = (from mwcard in xdoc1.Element("set").Element("cards").Elements("card")
                      select new card
                                 {
                                     id   = mwcard.Attribute("id").Value
                                    //Blocked here => cant access second property like Type ...
                                 }).ToList();

寻求帮助

0 个答案:

没有答案