xml_doc = open('test.xml').read()
    objectList1 = d1common.types.objectlist_serialization.CreateFromDocument(xml_doc, 'text/xml')
    print objectList1.toxml()
    json, content_type = objectList1.serialize('application/json')
    
    objectList2 = d1common.types.objectlist_serialization.CreateFromDocument(json, 'application/json')
    print '\n' + objectList2.toxml()

CreateFromDocument with 'text/xml' goes to the superclass and creates an object directly from there, and then casts it to the subclass. The CreateFromDocument call with 'application/json' create creates a subclass directly. The JSON object itself does not contain any information about the name of the root object.

-------


<?xml version="1.0" ?><ns1:objectList count="1000" start="0" total="100" xmlns:ns1="http://dataone.org/service/types/ObjectList/0.1"><objectInfo><identifier>hdl:10255/dryad.1228/mets.xml</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="SHA-1">3f56de593b6ffc536253b799b429453e3673fc19</checksum><dateSysMetadataModified>1970-01-19T04:53:32Z</dateSysMetadataModified><size>3666</size></objectInfo><objectInfo><identifier>hdl:10255/dryad.1073/mets.xml</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="SHA-1">aac6cca196fb6330d1013a10cce6a4604ca180d3</checksum><dateSysMetadataModified>1970-02-06T18:11:22Z</dateSysMetadataModified><size>3635</size></objectInfo><objectInfo><identifier>AnserMatrix.htm</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="MD5">0e25cf59d7bd4d57154cc83e0aa32b34</checksum><dateSysMetadataModified>1970-05-27T06:12:49Z</dateSysMetadataModified><size>11048</size></objectInfo></ns1:objectList>

<?xml version="1.0" ?><ns1:ObjectList count="1000" start="0" total="100" xmlns:ns1="http://dataone.org/service/types/ObjectList/0.1"><objectInfo><identifier>hdl:10255/dryad.1228/mets.xml</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="SHA-1">3f56de593b6ffc536253b799b429453e3673fc19</checksum><dateSysMetadataModified>1970-01-19T04:53:32Z</dateSysMetadataModified><size>3666</size></objectInfo><objectInfo><identifier>hdl:10255/dryad.1073/mets.xml</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="SHA-1">aac6cca196fb6330d1013a10cce6a4604ca180d3</checksum><dateSysMetadataModified>1970-02-06T18:11:22Z</dateSysMetadataModified><size>3635</size></objectInfo><objectInfo><identifier>AnserMatrix.htm</identifier><objectFormat>eml://ecoinformatics.org/eml-2.0.0</objectFormat><checksum algorithm="MD5">0e25cf59d7bd4d57154cc83e0aa32b34</checksum><dateSysMetadataModified>1970-05-27T06:12:49Z</dateSysMetadataModified><size>11048</size></objectInfo></ns1:ObjectList>

In [1]: import objectlist

incorrect:
In [2]: ol = objectlist.ObjectList()

In [3]: ol.toxml
Out[3]: <bound method ObjectList.toxml of <objectlist.ObjectList object at 0x1021d7790>>

In [4]: ol.toxml()
Out[4]: u'<?xml version="1.0" ?><ns1:ObjectList xmlns:ns1="http://dataone.org/service/types/ObjectList/0.1"/>'

In [5]: x = ol.toxml()

In [6]: ol2 = objectlist.Cre
objectlist.CreateFromDOM       objectlist.CreateFromDocument  

In [6]: ol2 = objectlist.CreateFromDocument(x)
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/Users/vieglais/Projects/D1_cicore/api-common-python/src/d1common/types/generated/objectlist.py", line 33, in CreateFromDocument
    instance = handler.rootObject()
  File "/Users/vieglais/lib/python/pyxb/binding/saxer.py", line 258, in rootObject
    raise pyxb.UnrecognizedElementError(dom_node=self.__rootObject)
UnrecognizedElementError: UnrecognizedElementError: No element binding available for {http://dataone.org/service/types/ObjectList/0.1}ObjectList

Correct:
In [1]: import objectlist

In [2]: ol = objectlist.objectList()

In [3]: ol.toxml()
Out[3]: u'<?xml version="1.0" ?><ns1:objectList xmlns:ns1="http://dataone.org/service/types/ObjectList/0.1"/>'

================================================

'''
Extends the PyXB generated class to enable serialization to and from CSV and 
JSON.
'''
import new
import d1common
import d1common.exceptions
import d1common.types.generated.systemmetadata

#===============================================================================

def toCSV(self, dialect='excel'):
  raise d1common.exceptions.NotImplemented('0.SystemMetaData.toCSV', 
         'Serializing SystemMetadata to CSV is not implemented.')


def fromCSV(self, data, dialect='excel'):
  raise d1common.exceptions.NotImplemented('0.SystemMetaData.fromCSV', 
         'De-serializing SystemMetadata from CSV is not implemented.')
  

def toJSON(self):
  raise d1common.exceptions.NotImplemented('0.SystemMetaData.toJSON', 
         'Serializing SystemMetadata to JSON is not implemented.')


def fromJSON(self, data):
  raise d1common.exceptions.NotImplemented('0.SystemMetaData.fromJSON', 
         'De-serializing SystemMetadata from JSON is not implemented.')


def systemMetadata():
  sysm = d1common.types.generated.systemmetadata.systemMetadata()
  sysm.toCSV = new.instancemethod(toCSV, sysm, sysm.__class__)
  sysm.fromCSV = new.instancemethod(fromCSV, sysm, sysm.__class__)
  sysm.toJSON = new.instancemethod(toJSON, sysm, sysm.__class__)
  sysm.fromJSON = new.instancemethod(fromJSON, sysm, sysm.__class__)
  

def CreateFromDocument(data, format='text/xml'):
  format = format.strip().lower()
  if format == d1common.MIMETYPES['xml']:
    sysm = d1common.types.generated.systemmetadata.CreateFromDocument( data )
    sysm.toCSV = new.instancemethod(toCSV, sysm, sysm.__class__)
    sysm.fromCSV = new.instancemethod(fromCSV, sysm, sysm.__class__)
    sysm.toJSON = new.instancemethod(toJSON, sysm, sysm.__class__)
    sysm.fromJSON = new.instancemethod(fromJSON, sysm, sysm.__class__)
    return sysm

  if format == d1common.MIMETYPES['json']:
    res = systemMetadata()
    return res.fromJSON(data)

  if format == d1common.MIMETYPES['csv']:
    res = systemMetadata()
    return res.fromCSV(data)

  raise ValueError('Unknown ObjectList serialization format: %s' % format)