Re: [xml] python xpath
- From: Daniel Veillard <veillard redhat com>
 
- To: Stefan Seefeld <seefeld sympatico ca>
 
- Cc: xml gnome org
 
- Subject: Re: [xml] python xpath
 
- Date: Thu, 15 Jul 2004 03:35:18 -0400
 
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__
attribute
(for text nodes only, of course), thus returning the actual text if 'print
node'
is called.
  would you feel like making a small patch to python/libxml.py
there is also the serialize() method but which is both more generic and 
more
complex than a simple text node dump.
right. Well, given that this is just a tiny convenience, I'd suggest just to
add
__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')
doc.serialize()
'<?xml 
version="1.0"?>\n<top>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n<doc>1</doc>\n</top>\n'
doc.get_content()
'\n1\n1\n1\n1\n1\n1\n1\n1\n1\n'
  Jumping on implementing the wrong semantic for __str__ could be painful
in the long run.
Daniel
-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]