游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2247|回复: 1

XmlSerializer write, no detail attributes

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2010-3-22 01:09:00 | 显示全部楼层 |阅读模式
I save a xml file by XMlSerializer, the result as below:

  <?xml version="1.0" ?>
- <SaveStageData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" n="12">
  <friendlist />
- <enemylist>
  <RoleCharacter /> <==== there no attributes I set
  </enemylist>
  <thinglist />
  </SaveStageData>

the enemylist is A List,its element is RoleCharacter.
RoleCharacter has some attributes, but in the xml file has no any attribute of

ObjectBase and   CCharacter. Do somebody know how to solve this problem?
I am sure one key point The RoleCharacter has data.


    public class RoleCharacter   
    {   
        public RoleCharacter()//for xml save must have a default constructor   
        {   
        }   
  
        public RoleCharacter(ENUM_OBJECT_CATEGORY nCate, ENUM_OBJECT_TYPE nType, int _nModelID, Point _point2D, Vector3 _translate, Vector3 _rotate, Vector3 _scale, CCharacter _char)   
        {   
            if (nType == ENUM_OBJECT_TYPE.Static)   
            {   
                m_object_base = new StaticObject(nCate, nType, _nModelID, _point2D, _translate, _rotate, _scale);   
            }   
            else if (nType == ENUM_OBJECT_TYPE.Dynamic)   
            {   
                m_object_base = new DynamicObject(nCate, nType, _nModelID, _point2D, _translate, _rotate, _scale);   
            }   
  
            m_charData = _char;   
        }   
  
        public ObjectBase GetObjectBase()   
        {   
            return m_object_base;   
        }   
  
        ObjectBase m_object_base;   
        CCharacter m_charData;         
    }   
  
  
    [Serializable]   
    [XmlInclude(typeof(RoleCharacter)), XmlInclude(typeof(CCharacter)),XmlInclude(typeof(ThingObject)), XmlInclude(typeof(ObjectBase)), XmlInclude(typeof(DynamicObject)), XmlInclude(typeof(StaticObject))]   
    public class SaveStageData   
    {   
        public SaveStageData()   
        {   
            friendlist = new List<RoleCharacter>();   
            enemylist = new List<RoleCharacter>();   
            thinglist = new List<ThingObject>();   
            n = 12;   
        }   
  
        public int n;   
        public List<RoleCharacter> friendlist;   
        public List<RoleCharacter> enemylist;   
        public List<ThingObject> thinglist;   
    }  
my blog: akira32 ?程之家 Yahoo

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
 楼主| 发表于 2011-3-26 22:37:00 | 显示全部楼层

Re:XmlSerializer write, no detail attributes

以解?Q了,public的??挡??Υ
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-7 04:40

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表