views:

143

answers:

1

Can some recommend an XML serializer that is element or attribute centric, and that doesn't use key-value pairs.

For example, GAE db.model has a to_xml() function but it writes out like this:

  <property name="firstname" type="string">John</property>
  <property name="lastname" type="string">Doe</property>
  <property name="city" type="string">Dallas</property>
  <property name="dateTimeCreated" type="gd:when">2009-09-30 19:45:45.975270</property>

From what I remember, these are much harder to map in XSLT tools than simple elements/attributes like this:

DESIRED OUTPUT

   <firstname>John</firstname>
   <lastname>Doe</lastname>
   <city>Dallas</city>
   <dateTimeCreated type="gd:when">2009-09-30 19:45:45.975270</dateTimeCreated>

I just tried the GNOSIS lib, and my first attempt worked, but also created name value pairs something like this:

  <attr name="__coredata__" type="dict" id="4760164835402068688" >
    <entry>
      <key type="string">firstname</key>
      <val type="string">John</val>
    </entry>
    <entry>
      <key type="string">lastname</key>
      <val type="string">Doe</val>
    </entry> 
    etc...

Thanks,

Neal Walters

+2  A: 

pyxslt.serialize looks closest to your specs but not a 100% map (for example, it doesn't record the type -- just turns everything into strings). Could still be a good basis from where to customize (maybe by copy / paste / edit, if it doesn't offer all the hooks you need for a cleaner customization).

Alex Martelli
Took a look at it, seems to require libxml2 (http://xmlsoft.org/) which is dependent on C, and thus cannot use with GAE.
NealWalters