I used gnosis to serialize jython object to xml.
Following is the class:

from net.grinder.script.Grinder import grinder

class person(object):
def __init__(self):
self._name = None

def getname(self):
return self._name
def setname(self,value):
self._name = value
name = property(getname, setname, "viji")

code is as follows:

from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
import java
import java.io.FileOutputStream
from java.lang import *
from personclass import person
import gnosis
from gnosis.xml.pickle import XML_Pickler

test1 = Test(1, "Test1")
request1 = test1.wrap(HTTPRequest())

class TestRunner:
def __call__(self):
grinder.logger.info("vij Hello World 1")
p1 = person()
p1.name = "viji"
xmlstring = XML_Pickler().dumps(p1)
# p2 = XML_Pickler().loads(xmlstring)
grinder.logger.info(" vij xml string " + str(xmlstring))

But I receive following output:

<?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject module="personclass" class="person" id="2">
<attr name="_name" type="string" value="viji" />

Whereas, I want the xml to look the one as follows:

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<person xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">

What is missing in the code? How can I get xml in the format I need?

On Wed, Mar 6, 2013 at 4:59 AM, Alan Kennedy <jython-dev@xhaus.com> wrote:

> I use Jython-2.5.2 for performance testing in Grinder 3.11
> How can I serialize an object to xml in Jython? What library files are needed to be added?

This sweb page has some promising approaches, which should workin jython.

serializing python objects to XML

In particular, the gnosisXML package should work.

You could also consider serialising to JSON


Then converting to XML. Although I would not bother with the XML step, I would probably just leave it in JSON.

Unless you have a specific XML related requirement.