Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Automatically exported from code.google.com/p/xstream-dot-net

Notifications You must be signed in to change notification settings

scottcowan/xstream-dot-net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xstream-dot-net

Introduction XStream.Net is the .Net version of Joe Walnes' XStream for Java. It is a simple library for serialisation/deserialisation to & from xml. The original code for this project was taken from Arne Vandamme's weblog which was a port of XStream for Java.

Usage

string serialisedObject = new XStream().ToXml(originalObject);
object deserialisedObject = new XStream().FromXml(serialisedObject);
Assert.AreEqual(originalObject, deserialisedObject);

Example say you have this class:

class SimpleClass
    {
      private int a; 
      private string x; 
    }

and you execute this code:

    XStream xstream = new XStream(); 
    SimpleClass simp = new SimpleClass(1, 2, "testString");   
    System.Console.WriteLine(xstream.ToXml(simp)); 

you get this:

<SimpleClass assembly="XstreamTest, Version=1.0.2342.35727, Culture=neutral, PublicKeyToken=null"><a>7</a><x>testString</x></SimpleClass>

Now if you add this line:

    xstream.Alias("SimpleClass", typeof(SimpleClass));

you get:

    <SimpleClass?><a>7</a><x>testString</x></SimpleClass?>

you are now free to read this class back in like this. (Note: this should work but it doesn't):

    string classString = "<SimpleClass><a>1</a><b>2</b><x>testString</x></SimpleClass?>"; 
    XStream xstream = new XStream(); 
    xstream.Alias("SimpleClass", typeof(SimpleClass)); 
    SimpleClass simpRead = xstream.FromXml(classString) as SimpleClass; 

About

Automatically exported from code.google.com/p/xstream-dot-net

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%