XML问题

winfpt 2016-06-09 07:10:52
我程序里要用到几种自定义的对象,一共是9个对象。
每一个对象有不同的属性(我把它定义成结构体了)。
其中对象1的属性是结构体LEDWindowsAttribute
对象2、对象3的属性是结构体TextWindowsAttribute
对象4、对象5、对象6、对象7、对象8、对象9的属性是结构体TimeWindowsAttribute

对象1是父节点(只有一个)
对象2------对象8是子节点。
我通过程序上的按钮操作动态的增加或删除子节点(用TreeView显示父节点和子节点,子节点里有重复对象比如有3个对象2,且子节点数量可能很多)。
我怎么才能将节点关系及对象属性序列化并存储成XML格式的文件,怎么反序列化XML文件解析还原得到TreeView上的树状结构和各个节点的属性。
希望大神给出思路和代码,小弟不胜感激!

TreeView上的表现形式如下所示
对象1的NodeText值
|----对象2的NodeText值
|----对象3的NodeText值
|----对象4的NodeText值
|----对象5的NodeText值
|----对象2的NodeText值
|----对象6的NodeText值
|----对象3的NodeText值
。。。。。。

///
///单行文字和多行文字对象窗口的属性
///
public struct TextWindowsAttribute
{
[XmlAttribute("NodeName")]
public string NodeName; //节点名字
[XmlElement("NodeText")]
public string NodeText; //节点文本
[XmlElement("NodeIndex")]
public int NodeIndex; //节点序号
[XmlElement("X")]
public int X; //X坐标
[XmlElement("Y")]
public int Y; //Y坐标
[XmlElement("Width")]
public int Width; //宽度
[XmlElement("Height")]
public int Height; //高度
[XmlElement("Text")]
public string Text; //文字
[XmlElement("FontName")]
public string FontName; //字体
[XmlElement("FontSize")]
public float FontSize; //字号
[XmlElement("FontBold")]
public bool FontBold; //是否粗体
[XmlElement("FontItalic")]
public bool FontItalic; //是否斜体
[XmlElement("FontUnderline")]
public bool FontUnderline; //是否有下划线
[XmlElement("FontColor")]
public int FontColor; //文字颜色
}

///
///时间对象窗口的属性
///
public struct TimeWindowsAttribute
{
[XmlAttribute("NodeName")]
public string NodeName; //节点名字
[XmlElement("NodeText")]
public string NodeText; //节点文本
[XmlElement("NodeIndex")]
public int NodeIndex; //节点序号
[XmlElement("X")]
public int X; //X坐标
[XmlElement("Y")]
public int Y; //Y坐标
[XmlElement("Width")]
public int Width; //宽度
[XmlElement("Height")]
public int Height; //高度
[XmlElement("FontName")]
public string FontName; //字体
[XmlElement("FontSize")]
public float FontSize; //字号
[XmlElement("FontBold")]
public bool FontBold; //是否粗体
[XmlElement("FontItalic")]
public bool FontItalic; //是否斜体
[XmlElement("FontUnderline")]
public bool FontUnderline; //是否有下划线
[XmlElement("FontColor")]
public int FontColor; //文字颜色
}

///
///LED显示屏对象窗口的属性
///
public struct LEDWindowsAttribute
{
[XmlAttribute("NodeName")]
public string NodeName; //节点名字
[XmlElement("NodeText")]
public string NodeText; //节点文本
[XmlElement("NodeIndex")]
public int NodeIndex; //节点序号
[XmlElement("X")]
public int X; //X坐标
[XmlElement("Y")]
public int Y; //Y坐标
[XmlElement("Width")]
public int Width; //宽度
[XmlElement("Height")]
public int Height; //高度
}
...全文
97 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧