Re: [xml] python xpath

On Wed, Jul 14, 2004 at 04:50:19PM -0400, Stefan Seefeld wrote:
Daniel Veillard wrote:

Daniel: it might indeed be convenient to return the content in the __str__
(for text nodes only, of course), thus returning the actual text if 'print
is called.

  would you feel like making a small patch to python/
there is also the serialize() method but which is both more generic and 
complex than a simple text node dump.

right. Well, given that this is just a tiny convenience, I'd suggest just to

__str__ = get_content

at line 264

What do you think ?

  Is dumping the content really the right thing to do ? Should __str__
really act as a serialization mechnism (in which case get_content or
serialize is the right handler) or rather as a debug mechanism (in
which case the type of the node sounds more important than it serialization).
  Also note that get_content() will return the string value of the
full subtree, is that really useful ? Except for a text node this 
does not sound the right operation, really, it not a representation
nor a good debug information:

doc = libxml2.parseFile('tst.xml')

  Jumping on implementing the wrong semantic for __str__ could be painful
in the long run.


Daniel Veillard      | Red Hat Desktop team
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]