def launch(*args, **kwargs): import pprint from amara.xpath.util import simplify source = args[0] expr = args[1] import amara doc = amara.parse(source) result = doc.xml_select(expr.decode('utf-8')) pprint.pprint(simplify(result)) return
def akara_xpath(body, ctype, **params): ''' select - XPath expression to be evaluated against the document tidy - 'yes' to tidy HTML, or 'no' Sample request: curl --request POST --data-binary "@foo.xml" --header "Content-Type: application/xml" "http://localhost:8880/akara.xpath?select=/html/head/title&tidy=yes" ''' if params.get("tidy") == 'yes': doc = html.parse(body) else: doc = amara.parse(body) result = simplify(doc.xml_select(params['select'].decode('utf-8'))) return str(result)