python中的XML对象序列化,Gnosis是否有替代方案? [英] XML object serialization in python, are there any alternatives to Gnosis?

查看:185
本文介绍了python中的XML对象序列化,Gnosis是否有替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在使用一个名为"gnosis-utils"的软件包,该软件包为Python提供了XML酸洗服务.这个类工作得相当不错,但是在过去的四年中,它似乎一直被它的开发人员所忽略.

For a while I've been using a package called "gnosis-utils" which provides an XML pickling service for Python. This class works reasonably well, however it seems to have been neglected by it's developer for the last four years.

当我们最初选择gnosis时,它是唯一的Python XML序列化工具. Gnosis的优点是它提供了一组类,其功能与内置的Python XML Pickler非常相似.它产生的XML使python开发人员易于阅读,但非python开发人员却感到困惑.

At the time we originally selected gnosis it was the only XML serization tool for Python. The advantage of Gnosis was that it provided a set of classes whose function was very similar to the built-in Python XML pickler. It produced XML which python-developers found easy to read, but non-python developers found confusing.

现在,这项技术已经发展起来,我们有一个新的要求:我们需要能够与喜欢Java或.Net的同事交换XML.这些非Python开发人员将不会使用Python-他们打算直接生产XML,因此我们需要简化XML的格式.

Now that the proejct has grown we have a new requirement: We need to be able to exchange XML with our colleagues who prefer Java or .Net. These non-python developers will not be using Python - they intend to produce XML directly, hence we have a need to simplify the format of the XML.

还有什么Gnosis的替代品.我们的要求:

So are there any alternatives to Gnosis. Our requirements:

  • 必须在Python 2.4/Windows x86 32bit上工作
  • 输出必须是XML,并且要尽可能简单
  • API必须尽可能类似于Pickle
  • 性能并不是很重要

当然,我们可以简单地改编Gnosis,但是我们更喜欢简单地使用已经提供所需功能的组件(假设它存在).

Of course we could simply adapt Gnosis, however we'd prefer to simply use a component which already provides the functions we requrie (assuming that it exists).

推荐答案

那么您要寻找的是一个Python库,该库为您的对象吐出任意XML?您不需要控制格式,因此不必费心去写一些可以迭代数据相关属性并使用现有工具之一生成XML的东西?

So what you're looking for is a python library that spits out arbitrary XML for your objects? You don't need to control the format, so you can't be bothered to actually write something that iterates over the relevant properties of your data and generates the XML using one of the existing tools?

这似乎是个坏主意.任意XML序列化听起来不是前进的好方法.包含pickle的所有功能的任何格式都将是丑陋,冗长且非常讨厌使用的.这不会很简单.它将无法很好地转换成Java.

This seems like a bad idea. Arbitrary XML serialization doesn't sound like a good way to move forward. Any format that includes all of pickle's features is going to be ugly, verbose, and very nasty to use. It will not be simple. It will not translate well into Java.

您的数据是什么样的?

如果您确切地告诉我们您需要泡菜的哪些方面(以及为什么lxml.objectify无法满足这些要求),我们将能够更好地为您提供帮助.

If you tell us precisely what aspects of pickle you need (and why lxml.objectify doesn't fulfill those), we will be better able to help you.

您是否考虑过使用JSON进行序列化?它易于解析,本机支持类似python的数据结构,并且具有广泛的支持.另外,它不会像原生的pickle模块那样对各种恶意代码开放您的代码.

Have you considered using JSON for your serialization? It's easy to parse, natively supports python-like data structures, and has wide-reaching support. As an added bonus, it doesn't open your code to all kinds of evil exploits the way the native pickle module does.

老实说,如果您绝对必须使用XML,那么您需要咬一口子并定义一种格式,并使用标准XML工具构建一个序列化程序.考虑JSON.

Honestly, you need to bite the bullet and define a format, and build a serializer using the standard XML tools, if you absolutely must use XML. Consider JSON.

这篇关于python中的XML对象序列化,Gnosis是否有替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆