restxq with html form get

Friday, 27 December 2013 · 1 message
E
e-letter27 Dec 2013 09:44 #

Readers,

A new file is trying to be created, with a html form using the element 'select'. The objective is to select from a menu and return a new html page after processing of the xquery function.

From the web page about http requests (http://docs.basex.org/wiki/RESTXQ#HTTP_Methods), where is the content type to be written in the xqm file?

(:~
: This module contains some basic examples for RESTXQ annotations
: @author BaseX Team
:)
module namespace page = 'http://basex.org/modules/web-page';

(:~
: This function generates the welcome page.
: @return HTML page
:)
declare
%rest:path("")
%output:method("xhtml")
%output:omit-xml-declaration("no")
%output:doctype-public("-//W3C//DTD XHTML Basic 1.1//EN")
%output:doctype-system("http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd")
function page:start()
as element(Q{http://www.w3.org/1999/xhtml}html)
{
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>BaseX HTTP Services</title>
		<link rel="stylesheet" type="text/css" href="static/style.css"/>
	</head>
	<body>
		<h3>Example 2</h3>
		<p>The next example presents how form data is processed via RESTXQ
and the POST method:</p>
		<form
				method='get'
				name='databasequeryform'
Quoted text · 1 line
>
				<p>
					<select
						name='booktitle'
Quoted text · 1 line
>
						<option>
							Everyday Italian
						</option>
						<option>
							Harry Potter
						</option>
					</select>
					<input
						type="submit"
						value='send'
						/>
				</p>
			</form>
	</body>
</html>
};
declare
%rest:path("/form")
%rest:GET
function page:post()
	{
		let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday
Italian')]/parent::*
		return $x
	};
declare
%rest:path("/put")
%rest:PUT("{$body}")
function page:put($body)
	{
		 || $body
	};

Extract of xml file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Edited by XMLSpy®, taken from http://www.w3schools.com-->
<?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>
<bookstore>
	<book
		category="COOKING">
		<title
			lang="en"
Quoted text · 1 line
>
			Everyday Italian
		</title>
		<author>Giada De Laurentiis</author>
		<year>2005</year>
		<price>30.00</price>
	</book>
...

⚡Generated with XQuery