xml - Python xpath not working? -


OK, this is starting to drive me a little bit crazy I have used several XML / Xpath libraries for Python Have tried, and can not find an easy way to get a stinkin '' title 'element'.

The latest attempt looks like this (using Amara):

  def view (req, url) for node in  

But this Does not print. My XML looks like this:

If I try to // title instead of //, then it gives everything as expected I know that XML has title , so what's the problem? Is this a name or something? If so, how can I fix it?


This does not work with any prefix, but it works:

  def view (req, url): req.content_type = 'Text / plain' doc = amara.parse (url, prefix = {'atom': 'http://www.w3.org/2005/Atom'}) req.write (str (Doc.xml_xpath ('// Atom: title '))  

You probably just focus on the name space of that document Which you want to deal with.

I see how to deal with namespace in Amara:

Edit: I did not make any edits using my code snippet Find out which Amara you are using, but depending on the docs I tried to adjust it as much as possible:

  def view (req, url): req.content_type = 'Text / plain' NS = {u'f ': u'http: //www.w3.org/2005/ atom', u't ': u' http: //purl.org/syndication/thread/1.0 '} Doc = amara.parse (urlopen (url), prefix = ns) req.write (str (doc.xml_ Xpath (u'f: title ')))  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -