Xquery results can be multiple documents. They get rendered as they should.

This commit is contained in:
sebd 2005-05-16 15:14:33 +00:00
parent 0856957b93
commit 164ba65d48
1 changed files with 22 additions and 7 deletions

View File

@ -100,15 +100,30 @@ class XQuery(things.Thing):
except RuntimeError, e:
logs.error("Error in query: %s" % e)
layout.append(html.p(_("Error in query: %s") % e))
else:
output = "\n".join([value.asString() for value in results])
return False
output = "\n".join([value.asString() for value in results])
try:
doc = libxml2.readDoc(output, None, None, 0)
except libxml2.treeError:
# output is not an XML document, let's try it as a list of docs.
results.reset()
try:
doc = libxml2.readDoc(output, None, None, 0)
div = html.div()
for value in results:
doc = libxml2.readDoc(value.asString(), None, None, 0)
element = self.newElement(doc.getRootElement())
element.generateXml(div)
layout.append(div)
print div.serialize()
except libxml2.treeError:
# output is not an XML document, considering it as plain text
layout.append(html.html(html.body(html.pre(output))))
else:
layout.append(doc.getRootElement())
# values are not whole XML docs. Let's put them in <p>.
results.reset()
div = html.div()
for value in results:
div.append(html.p(value.asString()))
layout.append(div)
else:
layout.append(doc.getRootElement())
return True
elements.registerElement(namespaces.yep.uri, "xquery", XQuery)