Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95964 > unrolled thread

XML Binding

Started byPalpandi <palpandi111@gmail.com>
First post2015-09-03 09:54 -0700
Last post2015-09-10 23:47 -0700
Articles 13 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  XML Binding Palpandi <palpandi111@gmail.com> - 2015-09-03 09:54 -0700
    Re: XML Binding Burak Arslan <burak.arslan@arskom.com.tr> - 2015-09-03 22:54 +0300
      Re: XML Binding Palpandi <palpandi111@gmail.com> - 2015-09-03 22:21 -0700
        Re: XML Binding Chris Angelico <rosuav@gmail.com> - 2015-09-04 15:36 +1000
        Re: XML Binding Laura Creighton <lac@openend.se> - 2015-09-04 08:46 +0200
        Re: XML Binding Laura Creighton <lac@openend.se> - 2015-09-04 08:54 +0200
    Re: XML Binding Lorenzo Sutton <lorenzofsutton@gmail.com> - 2015-09-04 10:11 +0200
    Re: XML Binding Palpandi <palpandi111@gmail.com> - 2015-09-07 06:42 -0700
      Re: XML Binding dieter <dieter@handshake.de> - 2015-09-09 10:20 +0200
      Re: XML Binding Stefan Behnel <stefan_ml@behnel.de> - 2015-09-09 11:44 +0200
      Re: XML Binding dieter <dieter@handshake.de> - 2015-09-10 08:30 +0200
    Re: XML Binding harirammanohar159@gmail.com - 2015-09-09 02:00 -0700
    Re: XML Binding Michele Simionato <michele.simionato@gmail.com> - 2015-09-10 23:47 -0700

#95964 — XML Binding

FromPalpandi <palpandi111@gmail.com>
Date2015-09-03 09:54 -0700
SubjectXML Binding
Message-ID<8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com>
Hi All,

Is there any module available in python standard library for XML binding? If not, any other suggestions.

Which is good for parsing large file?
1. XML binding
2. Creating our own classes


Thanks,
Palpandi

[toc] | [next] | [standalone]


#95971

FromBurak Arslan <burak.arslan@arskom.com.tr>
Date2015-09-03 22:54 +0300
Message-ID<mailman.96.1441310503.8327.python-list@python.org>
In reply to#95964
Hello,

On 09/03/15 19:54, Palpandi wrote:
> Hi All,
>
> Is there any module available in python standard library for XML binding? If not, any other suggestions.

lxml is the right xml library to use. You can use lxml's objectify or Spyne.

Here are some examples:

http://stackoverflow.com/questions/19545067/python-joining-and-writing-xml-etrees-trees-stored-in-a-list

> Which is good for parsing large file?
> 1. XML binding
> 2. Creating our own classes

If you're dealing with huge files, I suggest using just lxml and work
with raw data. Deserializing xml objects to python classes sure is nicer
but has performance overhead that gets more and more visible as the
amount of data you deal with grows.

Best,
Burak

[toc] | [prev] | [next] | [standalone]


#96007

FromPalpandi <palpandi111@gmail.com>
Date2015-09-03 22:21 -0700
Message-ID<5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com>
In reply to#95971
Thanks Burak.

lmxl is good. But it is not supported with python 2.5. Any other option?

[toc] | [prev] | [next] | [standalone]


#96008

FromChris Angelico <rosuav@gmail.com>
Date2015-09-04 15:36 +1000
Message-ID<mailman.126.1441345022.8327.python-list@python.org>
In reply to#96007
On Fri, Sep 4, 2015 at 3:21 PM, Palpandi <palpandi111@gmail.com> wrote:
> Thanks Burak.
>
> lmxl is good. But it is not supported with python 2.5. Any other option?

The latest version isn't. But PyPI has an older version which is:

https://pypi.python.org/pypi/lxml/3.3.6

You should be able to install that into a Python 2.5. Though if you
possibly can, I would recommend upgrading to 2.7.

ChrisA

[toc] | [prev] | [next] | [standalone]


#96012

FromLaura Creighton <lac@openend.se>
Date2015-09-04 08:46 +0200
Message-ID<mailman.128.1441349206.8327.python-list@python.org>
In reply to#96007
In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes:
>Thanks Burak.
>
>lmxl is good. But it is not supported with python 2.5. Any other option?
>-- 
>https://mail.python.org/mailman/listinfo/python-list

check and see what python you have.  If 2.6 or more recent, use lxml
If you have 2.5 use the slower elementtree.
https://docs.python.org/2/library/xml.etree.elementtree.html

If you pay attention to this
http://lxml.de/compatibility.html
you can mostly get away with writing your code once.

Laura

[toc] | [prev] | [next] | [standalone]


#96013

FromLaura Creighton <lac@openend.se>
Date2015-09-04 08:54 +0200
Message-ID<mailman.129.1441349704.8327.python-list@python.org>
In reply to#96007
In a message of Fri, 04 Sep 2015 08:46:33 +0200, Laura Creighton writes:
>In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes:
>>Thanks Burak.
>>
>>lmxl is good. But it is not supported with python 2.5. Any other option?
>>-- 
>>https://mail.python.org/mailman/listinfo/python-list
>
>check and see what python you have.  If 2.6 or more recent, use lxml
>If you have 2.5 use the slower elementtree.
>https://docs.python.org/2/library/xml.etree.elementtree.html
>
>If you pay attention to this
>http://lxml.de/compatibility.html
>you can mostly get away with writing your code once.
>
>Laura

I didn't know about the old versions still available from pip.  That
is probably a better idea.

Laura

[toc] | [prev] | [next] | [standalone]


#96014

FromLorenzo Sutton <lorenzofsutton@gmail.com>
Date2015-09-04 10:11 +0200
Message-ID<mailman.131.1441354275.8327.python-list@python.org>
In reply to#95964
Hi,

On 03/09/2015 21:54, Burak Arslan wrote:
> Hello,
>
> On 09/03/15 19:54, Palpandi wrote:
>> Hi All,
>>
>> Is there any module available in python standard library for XML binding? If not, any other suggestions.
>
> lxml is the right xml library to use. You can use lxml's objectify or Spyne.

I second lxml..

[...]
>> Which is good for parsing large file?
How large is large?

I have used lxml (coupled with pygtk) with very good results on XML 
files up to around 250Mb.

Lorenzo.

[toc] | [prev] | [next] | [standalone]


#96101

FromPalpandi <palpandi111@gmail.com>
Date2015-09-07 06:42 -0700
Message-ID<9b916796-623d-45d9-abe0-8bc7934ec42b@googlegroups.com>
In reply to#95964
Hi All,

Is it better to use pyxb than lxml?

What are the advantages of lxml and pyxb?

Thanks,
Palpandi

[toc] | [prev] | [next] | [standalone]


#96171

Fromdieter <dieter@handshake.de>
Date2015-09-09 10:20 +0200
Message-ID<mailman.258.1441786885.8327.python-list@python.org>
In reply to#96101
Palpandi <palpandi111@gmail.com> writes:

> Is it better to use pyxb than lxml?
>
> What are the advantages of lxml and pyxb?

"pyxb" has a different aim than "lxml".

"lxml" is a general purpose library to process XML documents.
It gives you an interface to the document's resources (elements,
attributes, comments, processing instructions) on a low level
independ from the document type.

"pyxb" is different: there, you start with an XML schema description.
You use "pyxb" to generate Python bindings for this schema.
With such a binding generated, "pyxb" can parse XML documents
following a known XML schema into the corresponding binding.
The binding objects expose child (XML) elements and (XML) attributes as
attributes of the binding object. Thus, the Python interface
(as defined by the binding) is highly dependent on the type (aka XML schema)
of the document.


I use "lxml" for either simple XML processing or when the XML documents
are not described by an XML schema. I use "pyxb" when the XML documents
has an associated complex schema and the processing is rather complex.

[toc] | [prev] | [next] | [standalone]


#96180

FromStefan Behnel <stefan_ml@behnel.de>
Date2015-09-09 11:44 +0200
Message-ID<mailman.260.1441791875.8327.python-list@python.org>
In reply to#96101
dieter schrieb am 09.09.2015 um 10:20:
> Palpandi writes:
>> Is it better to use pyxb than lxml?
>>
>> What are the advantages of lxml and pyxb?
> 
> "pyxb" has a different aim than "lxml".
> 
> "lxml" is a general purpose library to process XML documents.
> It gives you an interface to the document's resources (elements,
> attributes, comments, processing instructions) on a low level
> independ from the document type.

lxml's toolbox is actually larger than that. There's also lxml.objectify
which provides a Python object interface to the XML tree, similar to what
data binding would give you. And you can stick your own Element object
implementations into it if you feel a need to simplify the API itself
and/or adapt it to a given document format.

http://lxml.de/objectify.html

Stefan

[toc] | [prev] | [next] | [standalone]


#96242

Fromdieter <dieter@handshake.de>
Date2015-09-10 08:30 +0200
Message-ID<mailman.308.1441866683.8327.python-list@python.org>
In reply to#96101
Stefan Behnel <stefan_ml@behnel.de> writes:

> dieter schrieb am 09.09.2015 um 10:20:
>> Palpandi writes:
>>> Is it better to use pyxb than lxml?
>>>
>>> What are the advantages of lxml and pyxb?
>> 
>> "pyxb" has a different aim than "lxml".
>> 
>> "lxml" is a general purpose library to process XML documents.
>> It gives you an interface to the document's resources (elements,
>> attributes, comments, processing instructions) on a low level
>> independ from the document type.
>
> lxml's toolbox is actually larger than that. There's also lxml.objectify
> which provides a Python object interface to the XML tree, similar to what
> data binding would give you. And you can stick your own Element object
> implementations into it if you feel a need to simplify the API itself
> and/or adapt it to a given document format.
>
> http://lxml.de/objectify.html

This is nice - but still quite far from the schema support of "pyxb".

The "pyxb" binding generation generates a Python class for each type
defined in the schema. You just instantiate such a class, populate
the resulting object (in the normal Python way) and either use
it in the construction of larger objects or serialize it as XML -- no
need to worry about special construction ("objectivity.DataElement",
"objectivity.SubElement", ...), no need to worry about xml namespaces.

[toc] | [prev] | [next] | [standalone]


#96175

Fromharirammanohar159@gmail.com
Date2015-09-09 02:00 -0700
Message-ID<0618b133-a063-4752-85b7-1ee7518e5262@googlegroups.com>
In reply to#95964
On Thursday, 3 September 2015 22:25:06 UTC+5:30, Palpandi  wrote:
> Hi All,
> 
> Is there any module available in python standard library for XML binding? If not, any other suggestions.
> 
> Which is good for parsing large file?
> 1. XML binding
> 2. Creating our own classes
> 
> 
> Thanks,
> Palpandi

Hey you can use internal package itself, argparse will work good...even xmltree also...

[toc] | [prev] | [next] | [standalone]


#96326

FromMichele Simionato <michele.simionato@gmail.com>
Date2015-09-10 23:47 -0700
Message-ID<98854a42-cbf3-44de-baea-47a4d89a5381@googlegroups.com>
In reply to#95964
On Thursday, September 3, 2015 at 6:55:06 PM UTC+2, Palpandi wrote:
> Hi All,
> 
> Is there any module available in python standard library for XML binding? If not, any other suggestions.
> 
> Which is good for parsing large file?
> 1. XML binding
> 2. Creating our own classes
> 
> 
> Thanks,
> Palpandi

I am one who has just abandoned lxml for xml.etree in the standard library. The reasons for that change were:

1. we had issues compiling/installing lxml on different platforms
2. we had instabilities from one version to the other for what we wanted to do (XML validation with an XSD schema)

At the end we solved everything by replacing the XSD validation with a custom validation (which we had to do anyway); at that point the need for lxml disappeared and ElementTree did everything we wanted, except providing the line error in case of invalid files, which was easy to add. It was also smaller, easier to understand and to customize. Its speed was more than enough.

However I hear that everybody else is happy with lxml, so YMMV.

    
  Michele

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web