Reputation: 11
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.
Upvotes: 1
Views: 158
Reputation: 292725
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 the Mode
property, and put this property in a Action
class that maps to the <action>
element.
Upvotes: 2