Re: [xml] python xpath



On Tue, Jul 13, 2004 at 05:21:19PM -0400, Stefan Seefeld wrote:
Jason Jesso wrote:
flight = self.ctxt.xpathEval( "table/tr/td/a/text()" )
print flight[0]

I am evaluating this xpath expression using python's libxml2.

How can I get the actual text data?  When I print the result set I get 
text
node information, like the address and stuff.

The node's 'content' (python) attribute will contain the actual text (if it 
is
a text node).

  Another way is to do
    flight_str=self.ctxt.xpathEval( "string(table/tr/td/a/text()[0])" )
i.e. make the conversion directly at the XPath level and get a string back.

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.

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]