I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works would be great.
-
6XML is XML. If a library can't parse valid XML properly then it's the library that's at fault, not any sense of "interoperability".Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2010-03-22 13:27:31 +00:00Commented Mar 22, 2010 at 13:27
-
I don't care who is guilty in this situation. bottom line is that frameworks are incompatible. and I'm just want a recommendation on 2 frameworks that can play nice together. e.g see this old.nabble.com/…ApriOri– ApriOri2010-03-23 09:37:03 +00:00Commented Mar 23, 2010 at 9:37
2 Answers
As Ignacio says, XML is XML. On the python side, I recommend using lxml, unless you have more specific needs that are better met by another library. If you are restricted to the standard library, look at ElementTree or cElementTree, which are also excellent, and which inspired (and are functionally mostly equivalent to) lxml.etree.
Edit: On closer look, it seems you are not just looking for XML, but for XML representations of objects. For this, check out lxml.objectify, or Amara. I haven't tried using them for interoperability with Java, but they're worth a try. If you're just looking for a way to do data exchange, you might also try custom JSON objects.
Comments
The issue your are probably having is the default format of the Python and Java libraries you are using to marshal your objects. Any decent libraries including JAXB allows customisation of how objects should be represented in XML.
You need to decide what the structure of your XML should be then use your libraries features to consume and emit your XML structure rather than relying on the defaults which would never be the same across different libraries in different programming languages.