Deprecated Garbage Collections – Kenny Lee Chee Wei

A truckload of garbage by Kenny Lee Chee Wei

Marshalling Objects To/From XML (Java and Python)

with one comment

Python (Using PyXML)

#
# Install PyXML from http://pyxml.sourceforge.net/
#

from xml.marshal.generic import Marshaller, Unmarshaller

class Company:

def __init__(self, name, year_founded, ceo):
self.name = name
self.year_founded =year_founded
self.ceo = ceo

def __str__(self):
return "%s %s %s" % (self.name, self.year_founded, self.ceo)

c = Company('Google Inc.', '1998', 'Eric Schmidt')

# Marshalling
marshal = Marshaller()
xml = marshal.dumps(c)
print xml

# Un-Marshalling
um = Unmarshaller()
obj = um.loads(xml)
print obj

Java (Using XStream)

The people at ThoughtWorks makes it easy. Just read here.

Advertisements

Written by kennii

August 7, 2007 at 7:35 am

Posted in Java, Python

One Response

Subscribe to comments with RSS.

  1. Hiya! Just checking links out from the dune forums and saw your blog link. Nicely written.

    This python stuff makes me want to look into python again. Just played around with it a little bit, but never really got into the basics so I could write straight without a manual.

    See ya!

    Gerard Toonstra

    August 30, 2007 at 4:53 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: