使用元数据反序列化 Xml
我想将这个 Xml : 反序列化
<Content id="1">
<Element key="Description">Bla bla bla</Element>
<Element key="Title">The title</Element>
</Content>
到这个类中:
public class Content
{
[XmlAttribute(AttributeName = "id")]
public string Id
{
get { return _id; }
set { _id = value; }
}
[XmlAttribute(AttributeName = "description")]
public string Description
{
get;
set;
}
[XmlAttribute(XmlElement = "title")]
public string Title
{
get;
set;
}
}
我的问题是我不知道如何将正确属性的文本放入类属性中。
谢谢
I want to deserialize this Xml :
<Content id="1">
<Element key="Description">Bla bla bla</Element>
<Element key="Title">The title</Element>
</Content>
into this classes :
public class Content
{
[XmlAttribute(AttributeName = "id")]
public string Id
{
get { return _id; }
set { _id = value; }
}
[XmlAttribute(AttributeName = "description")]
public string Description
{
get;
set;
}
[XmlAttribute(XmlElement = "title")]
public string Title
{
get;
set;
}
}
My problem is that i don't know how i can put the text of the right attribute in the class property.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为
XML 节点创建一个辅助类。另一种选择是实现
IXmlSerialized
接口:
You need to create a helper class for the
<element>
XML node.Another option would be to implement the
IXmlSerializable
interface: