Hello again. =:o)
import System.*;
import System.Xml.Serialization.*;
import System.IO.*;
public class Group1
{
// The XmlTextAttribute with type set to string informs the
// XmlSerializer that strings should be serialized as XML text.
/** @attribute XmlText(String.class) */
/** @attribute XmlElement(int.class) */
/** @attribute XmlElement(double.class) */
public Object all[] = new Object[]
{
(Int32)321, "One", (Int32)2,
(System.Double)3.0, "Two" };
}
public class Group2
{
// HERE______
/** @attribute XmlElement(GroupType.class, ElementName = "GroupType") */
public GroupType type = new GroupType();
// __________
}
public class GroupType
{
private int member;
public void setMember(int n)
{
member = n;
}
public static int small;
public static int medium;
public static int large;
}
public class Group3
{
// HERE_____
/** @attribute XmlElement(DateTime.class, ElementName = "DateTime") */
public DateTime creationTime = DateTime.get_Now();
// _________
}
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.SerializeArray("XmlText1.xml");
t.SerializeEnum("XmlText2.xml");
t.SerializeDateTime("XmlText3.xml");
}
private void SerializeArray(String filename)
{
XmlSerializer ser = new XmlSerializer(Group1.class.ToType());
Group1 myGroup1 = new Group1();
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup1);
writer.Close();
}
private void SerializeEnum(String filename)
{
XmlSerializer ser = new XmlSerializer(Group2.class.ToType());
Group2 myGroup = new Group2();
myGroup.type.setMember(GroupType.medium);
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup);
writer.Close();
}
private void SerializeDateTime(String filename)
{
XmlSerializer ser = new XmlSerializer(Group3.class.ToType());
Group3 myGroup = new Group3();
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup);
writer.Close();
}
}
Regards,
Lars-Inge Tønnessen
www.larsinge.com