Logo

Programming-Idioms

New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import orange.serialization._;
import orange.serialization.archives._;
import std.file;
auto archive = new XmlArchive!(char);
auto serializer = new Serializer(archive); 
serializer.serialize(x);
write("data.xml", archive.data);
import "encoding/xml"
import "io/ioutil"
buffer, err := xml.MarshalIndent(x, "", "  ")
if err != nil {
	return err
}
err = ioutil.WriteFile("data.xml", buffer, 0644)
require_once('XML/Serializer.php');
class Test
{
    public $f1;
    private $f2;

    public function __construct($f1, $f2)
    {
        $this->f1 = $f1;
        $this->f2 = $f2;
    }
}

$x = new Test('foo', 42);

$options = array(
  XML_SERIALIZER_OPTION_INDENT        => '    ',
  XML_SERIALIZER_OPTION_RETURN_RESULT => true
  );

$serializer = new XML_Serializer($options);
$result = "<?xml version=\"1.0\"?>\n" . $serializer->serialize($x);
file_put_contents('data.xml', $result);
use XML::LibXML qw();
$x->toFile('data.xml');
import pyxser as pyx
# Python 2.5 to 2.7
# Use pickle or marshall module
class TestClass(object):
    a = None
    b = None
    c = None

    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

tst = TestClass("var_a", "var_b", "var_c")
ser = pyx.serialize(obj=tst, enc="utf-8")
print(ser)