c# - 如何使用 xmlserializer 序列化此名称列表?
问题描述
获取此示例 XML:
<Teaching StudyPoint="0" Description="xx" OtherDiscussionVideo="True" VideoAfterStudentItem="False">
<Theme>Test 1</Theme>
<SourceMaterial>Material 1</SourceMaterial>
<Names>
<Name Class="2">a</Name>
<Name Class="3">b</Name>
<Name Class="1">b</Name>
</Names>
</Teaching>
到目前为止,我已经设法为序列化创建了这个类:
namespace OutlookCalIFConsole.MWBData
{
public class Teaching
{
[XmlAttribute]
public int StudyPoint
{
get => _StudyPoint; set => _StudyPoint = value;
}
private int _StudyPoint;
[XmlAttribute]
public string Description
{
get => _Description; set => _Description = value;
}
private string _Description;
[XmlAttribute]
public bool OtherDiscussionVideo
{
get => _OtherDiscussionVideo; set => _OtherDiscussionVideo = value;
}
private bool _OtherDiscussionVideo;
[XmlAttribute]
public bool VideoAfterStudentItem
{
get => _VideoAfterStudentItem; set => _VideoAfterStudentItem = value;
}
private bool _VideoAfterStudentItem;
public string Theme
{
get => _Theme; set => _Theme = value;
}
private string _Theme;
public string SourceMaterial
{
get => _SourceMaterial; set => _SourceMaterial = value;
}
private string _SourceMaterial;
public Teaching()
{
_OtherDiscussionVideo = false;
_VideoAfterStudentItem = false;
_StudyPoint = 0;
_Description = "";
_Theme = "";
_SourceMaterial = "";
}
}
}
如何序列化Name
值列表?
解决方案
尝试在Teaching
课堂内进行以下操作:
public class Teaching {
[XmlArrayItem("Name")]
public Name[] Names;
}
推荐阅读
- python - 在 Kivy 中旋转十张随机图像
- javascript - 修复 js 传播运算符复制具有相同键的深度值
- java - Elasticsearch 高级 REST 客户端无法通过 https 连接
- rubygems - Ruby 中连字符的标记
- json - JSONiq - 如何将数组转换为序列?
- javascript - 从节点后端目录发送图像/文件以响应前端
- firebase - 参考 firebase 功能中使用的 firebase 项目
- reactjs - 试图让网站更新 googlesheets
- android - 如何触发 Android 操作系统杀死我的后台服务以进行测试?
- kubernetes - 使用 Helm 设置 Kubernetes 命名空间和角色