function XMLCallback(event) % XMLCallback - Callback called by modelit.webserver.Server object for % generating an XML response. % % CALL: % XMLCallback(event) % % INPUT: % event: <modelit.webserver.HttpExchange> % with the request data and methods to generate a response. % % OUTPUT: % No output, a response with an XML string is return to the client. % % EXAMPLE: % server = modelit.web.server.Server(8081, @XMLCallback).start() % % % Open a webbrowser and type: http://localhost:8081 in the address bar % % Now an xml message appears in the browser. % % Copyright 2020 Modelit, www.modelit.nl % Generate the response using the event send by the server response = XML(event); % Set the MIME type % See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types event.addResponseHeader('Content-Type', 'text/xml'); % Send the response back to the client, with statuscode 200 (OK) % See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status event.send(200, response); %__________________________________________________________________________ function text = XML(event) % XML - Make a simple HTML string using the HttpExchange methods % % CALL: % text = XML(event) % % INPUT: % event: % <modelit.web.server.HttpExchange> with request details and methods % to send the response back to the client. % % OUTPUT: % text: % <string> with an xml string % Make a simple XML text = sprintf('<?xml version="1.0" ?><response><time>%s</time><method>%s</method><from>%s</from></response>',... datestr(now),event.getRequestMethod,event.getRemoteAddress);