By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,449 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,449 IT Pros & Developers. It's quick & easy.

related to XMLSerialization

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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;
}
}
}
--
Roman S. Golubin
ICQ UIN 63253392
go*****************@arhcity.ru
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.