R
ranganadh
Hi all group members,
I am looking for code-sample to serialize object into XML format,
in different formats suppose think that i have one class,
[XmlRoot("MY-Employes")]
[Serializable]
public class Emp :ISerializable
{
public enum MySex
{
MALE=100,FEMALE=200,NOINFO=0
}
IFormatter = System.Runtime.Serialization.Formatters.soap
private string fname;
private string lname;
private string full_name;
private int sex=0;
[XmlElement("First_Name")]
public string MyFname
{
get
{
if (fname != null)
return fname;
else
return "NULL";
}
set
{
fname = value;
}
}
[XmlElement("Last_Name")]
public string MyLName
{
get
{
if(lname != null)
return lname;
else return "NULL";
}
set
{
lname = value;
}
}
[XmlElement("FULL_NAME")]
public string MyFullName
{
get
{
if (full_name != null)
return full_name;
else
return "NULL";
}
set
{
full_name = value;
}
}
[XmlAttribute("sex")]
public MySex MY_Sex
{
get
{
if (sex == 0)
return MySex.NOINFO;
else if (sex == 100)
return MySex.MALE;
else return MySex.FEMALE;
}
set
{
sex = 100;
}
}
void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("_Identity", this.sex);
info.AddValue("_Name", this.sex);
}
public Emp()
{
}
}
by defult it was giving,
<?xml version="1.0" encoding="utf-16"?>
<MY-Employes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" sex="MALE">
<First_Name>Ranganadh</First_Name>
<Last_Name>Kodali</Last_Name>
<FULL_NAME>NULL</FULL_NAME>
</MY-Employes>
what happen, is i am exposing my service's to the two different client
applications, one client is required in one format, and other client
is required same set of data, but in other format,
is there any procedure, will help to produce, these kind of different
format's of XML file, without changing the code file. what i am
looking for, procedure that take XSD from file system, and
serialization should take according to that specified XML definition,
so i feel it will give a grater flexibility to change my structure
later on with changing the code ..
I am looking for code-sample to serialize object into XML format,
in different formats suppose think that i have one class,
[XmlRoot("MY-Employes")]
[Serializable]
public class Emp :ISerializable
{
public enum MySex
{
MALE=100,FEMALE=200,NOINFO=0
}
IFormatter = System.Runtime.Serialization.Formatters.soap
private string fname;
private string lname;
private string full_name;
private int sex=0;
[XmlElement("First_Name")]
public string MyFname
{
get
{
if (fname != null)
return fname;
else
return "NULL";
}
set
{
fname = value;
}
}
[XmlElement("Last_Name")]
public string MyLName
{
get
{
if(lname != null)
return lname;
else return "NULL";
}
set
{
lname = value;
}
}
[XmlElement("FULL_NAME")]
public string MyFullName
{
get
{
if (full_name != null)
return full_name;
else
return "NULL";
}
set
{
full_name = value;
}
}
[XmlAttribute("sex")]
public MySex MY_Sex
{
get
{
if (sex == 0)
return MySex.NOINFO;
else if (sex == 100)
return MySex.MALE;
else return MySex.FEMALE;
}
set
{
sex = 100;
}
}
void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("_Identity", this.sex);
info.AddValue("_Name", this.sex);
}
public Emp()
{
}
}
by defult it was giving,
<?xml version="1.0" encoding="utf-16"?>
<MY-Employes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" sex="MALE">
<First_Name>Ranganadh</First_Name>
<Last_Name>Kodali</Last_Name>
<FULL_NAME>NULL</FULL_NAME>
</MY-Employes>
what happen, is i am exposing my service's to the two different client
applications, one client is required in one format, and other client
is required same set of data, but in other format,
is there any procedure, will help to produce, these kind of different
format's of XML file, without changing the code file. what i am
looking for, procedure that take XSD from file system, and
serialization should take according to that specified XML definition,
so i feel it will give a grater flexibility to change my structure
later on with changing the code ..