Python XML + Java XML interoperability
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.开发者_运维百科
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.
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.
精彩评论