related to XMLSerialization

K

Keshav

Hi

While i'm doing XML serialization in C# class.... I have the following
problem...

I have an class by name "Operation"

In that i have two variables Id and Name and one more enum variable Mode...
Mode has got values { Manual , Automatic }

I am able to make Id and Name variable as XML Attribute...

I want the mode should be represented as

either <Mode><Automatic/></Mode> or

<Mode><Manual/></Mode>

The Operation object should get serialized as

<Operation Id="Operation1" Name="ship">
<Description>Ship from stock or production</Description>
<Mode>
<Automatic/>
</Mode>
</Operation>

My code looks like

public enum ModeEnum {Manual,Automatic}

public class WFActivity : WFProperty
{
private string _id;
private string _name;
private string _description;
private ModeEnum modeenum;

[XmlAttribute("Id")]
/* sets or gets id */
public string Id
{
get
{
return _id;
}
set
{
_id = value;
}
}

[XmlAttribute("Name")]
/* sets or gets name */
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}

[XmlElement("Description")]
/* sets or gets description */
public string Description
{
get
{
return _description;
}
set
{
_description = value;
}
}
}

Pls throw some light on this.

Thanks in Advance
Keshav
 
R

Roman S. Golubin

Hi Keshav!
While i'm doing XML serialization in C# class.... I have the following
problem...

I have an class by name "Operation"

In that i have two variables Id and Name and one more enum variable Mode...
Mode has got values { Manual , Automatic }

I am able to make Id and Name variable as XML Attribute...

I want the mode should be represented as

either <Mode><Automatic/></Mode> or

<Mode><Manual/></Mode>

The Operation object should get serialized as

<Operation Id="Operation1" Name="ship">
<Description>Ship from stock or production</Description>
<Mode>
<Automatic/>
</Mode>
</Operation>

My code looks like

public enum ModeEnum {Manual,Automatic}

public class WFActivity : WFProperty
{
private string _id;
private string _name;
private string _description;
private ModeEnum modeenum;
[skip...]

Pls throw some light on this.

[XmlElement("Mode")]
public ModeType Mode = new ModeType();
public class ModeType
{
ModeEnum _modeenum;
[XmlChoiceIdentifier("Value")]
[XmlElement("Manual")]
[XmlElement("Automatic")]
public string qq = "";
[XmlIgnore]
public ModeEnum Value
{
get
{
return _modeenum;
}
set
{
_modeenum = value;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top