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 
node information, like the address and stuff.

The node's 'content' (python) attribute will contain the actual text (if it 
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__ 
(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 more
complex than a simple text node dump.


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]