反序列化 XML
我正在尝试访问 xml 中的节点
来执行特定的
。
<controller name="Job">
<roles>
<role>1</role>
<role>3</role>
<role>4</role>
</roles>
<actions>
<action name="Index">
<roles>
<role>1</role>
<role>4</role>
</roles>
<accessmode>1</accessmode>
</action>
<action name="Warning">
<roles>
<role>1</role>
<role>3</role>
</roles>
<accessmode>3</accessmode>
</action>
</actions>
</controller>
我尝试使用下面的代码。
private string mode;
[XmlArrayItem(ElementName = "action")]
[XmlElement(ElementName = "accessmode")]
public string Mode
{
get { return mode; }
set { mode = value; }
}
由于
是我尝试过的 arrayitem 下的元素。 但是,我得到的值为空。任何帮助将不胜感激。
I am trying to access the node <accessmode>
in the xml for a specific <action>
.
<controller name="Job">
<roles>
<role>1</role>
<role>3</role>
<role>4</role>
</roles>
<actions>
<action name="Index">
<roles>
<role>1</role>
<role>4</role>
</roles>
<accessmode>1</accessmode>
</action>
<action name="Warning">
<roles>
<role>1</role>
<role>3</role>
</roles>
<accessmode>3</accessmode>
</action>
</actions>
</controller>
I tried with the below code.
private string mode;
[XmlArrayItem(ElementName = "action")]
[XmlElement(ElementName = "accessmode")]
public string Mode
{
get { return mode; }
set { mode = value; }
}
Since the <accessmode>
is an element under the arrayitem of I tried so.
But, I am getting the value as null. Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对
XmlArrayItem
属性的使用不正确。它用于集合属性来指定如何序列化集合的项目。您应该从Mode
属性中删除此属性,并将此属性放入映射到
元素的Action
类中。Your usage of the
XmlArrayItem
attribute is incorrect. It is used on collection properties to specify how the items of the collection are serialized. You should remove this attribute from theMode
property, and put this property in aAction
class that maps to the<action>
element.