- http://stackoverflow.com/questions/1186743/replacement-for-xml-serialization
- http://code.google.com/apis/protocolbuffers/docs/javatutorial.html
- [Great] http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization
- http://www.developer.com/net/csharp/article.php/3110371/SerializationDeserialization-in-NET.htm
- [Great] http://www.dotnetjohn.com/articles.aspx?articleid=173
public class Movie
{
public string Name
{ get; set; }
public int Rating
{ get; set; }
public DateTime ReleaseDate
{ get; set; }
}
{
public string Name
{ get; set; }
public int Rating
{ get; set; }
public DateTime ReleaseDate
{ get; set; }
}
STEP 2: Serialize it to Xml using the XmlSerializer class:
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
It would produce an XML file, named movie.xml, as:
<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Title>Starship Troopers</Title>
<Rating>6.9</Rating>
<ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Title>Starship Troopers</Title>
<Rating>6.9</Rating>
<ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>
STEP 3: Modify the Xml file and deserialize (update and re-hydrate) the .net object from the xml file:
static Movie DeserializeFromXML()
{
XmlSerializer deserializer = new XmlSerializer(typeof(Movie));
TextReader textReader = new StreamReader(@"C:\movie.xml");
Movie movie = (Movie)deserializer.Deserialize(textReader);
textReader.Close();
return movie;
}
{
XmlSerializer deserializer = new XmlSerializer(typeof(Movie));
TextReader textReader = new StreamReader(@"C:\movie.xml");
Movie movie = (Movie)deserializer.Deserialize(textReader);
textReader.Close();
return movie;
}
Flex Developer in India- Get the cheap and best flex developer, flex designer, flex application developer, flex application development, flex application design and much more at flexdeveloper.in. We also outsource flex work to freelancers.
ReplyDelete