Форум сайта python.su
Имеется код:
# -*- coding: utf-8 -*-
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from xml.dom.minidom import parseString
import xpath
class TestPage(webapp.RequestHandler):
def get(self):
xml = u'<?xml version="1.0" encoding="utf-8"?><root><p>Вопрос1<p>Ответ1</p></p><p>Вопрос2<p>Ответ2</p></p></root>'
#xml = u'<?xml version="1.0" encoding="utf-8"?><root><p>Qwestion1<p>Answer1</p></p><p>Qwestion2<p>Answer2</p></p></root>'
doc = parseString(xml)
answ = xpath.find(u'/root/p[contains(., "Вопрос1")]/p', doc)[0].childNodes[0].nodeValue
#answ = xpath.find(u'/root/p[contains(., "Qwestion1")]/p', doc)[0].childNodes[0].nodeValue
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
self.response.out.write('Answ: ')
self.response.out.write(answ)
application = webapp.WSGIApplication([('/', TestPage)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Офлайн