从xml创建python对象表示的模块 [英] module to create python object representation from xml

查看:67
本文介绍了从xml创建python对象表示的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种易于处理的python本机模块,以便从xml创建python对象表示形式.

I'm searching for an easy to handle python native module to create python object representation from xml.

我通过Google找到了几个模块(其中一个是 XMLObject ),但是没有找到?不想尝试所有这些.

I found several modules via google (one of them is XMLObject) but didn't want to try out all of them.

您认为做这种事情的最好方法是什么?

What do you think is the best way to do such things?

编辑:我想念的是我想生成的XML不是我生成的.这是一个现有的XML文件,其结构我无法控制.

I missed to mention that the XML I'd like to read is not generated by me. It's an existing XML file in a structure of which I have no control over.

推荐答案

您说您想要一个 object 表示形式,我将其解释为表示节点成为对象,以及该对象的属性和子元素.节点表示为对象的属性(可能根据某些架构).我相信XMLObject就是这样做的.

You say you want an object representation, which I would interpret to mean that nodes become objects, and the attributes and children of the node are represented as attributes of the object (possibly according to some Schema). This is what XMLObject does, I believe.

我知道一些软件包. 4Suite 包含一些用于执行此操作的工具,我相信 Amara 专门实现了此功能(建立在4Suite的基础上).您还可以使用 lxml.objectify ,该方法受Amara和

There are some packages that I know of. 4Suite includes some tools to do this, and I believe Amara specifically implements this (built on top of 4Suite). You can also use lxml.objectify, which was inspired by Amara and gnosis.xml.objectify.

当然,第三个选择是,给定XML的具体表示形式(使用ElementTree或lxml),您可以围绕它构建自己的自定义模型. lxml.html 就是一个例子,它使用一些特定于HTML的功能扩展了lxml的基本接口.

Of course a third option is, given a concrete representation of the XML (using ElementTree or lxml) you can build your own custom model around that. lxml.html is an example of that, extending the base interface of lxml with some HTML-specific functionality.

这篇关于从xml创建python对象表示的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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