basex

How to include HTML5 DOCTYPE in HTTP response


When using BaseX for developing a web application, I'd like to return HTML and include the DOCTYPE that is typical for HTML5, namely <!DOCTYPE html> I've noticed that if I set up a RESTXQ function and include the %output:method('html') annotation, there is no default DOCTYPE. If the function returns a sequence where the first item is the string "<!DOCTYPE html>" and the second is an <html> element, the web server escapes the angle brackets as &lt;!DOCTYPE html&gt; Is there a way to disable character escaping? If I include %output:doctype-system('html') then the web server provides <!DOCTYPE html SYSTEM "html"> which isn't quite right. Is there a way to suppress SYSTEM "html"?

I'm not seeing anything on the RESTXQ page of the BaseX documentation about using the HTML5 DOCTYPE, and the draft RESTXQ spec I found at http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html doesn't mention DOCTYPE at all.


Solution

  • The best solution is to output the result as HTML5, which can be done with the html-version serialization parameter:

    declare 
      %rest:path('/test')
      %output:method('html')
      %output:html-version('5')
    function local:test() {
      <html>Welcome</html>
    };