Hi Morgan,
You need to keep in mind that xsltforms runs at browser side, so uri to data
goes through your MarkLogic HTTP app server first. It means that /test/data.xml
will resolve to a file among the modules, and the PUT action won’t update it.
You need to put a small xquery in between to make it work. Something like:
xquery version "1.0-ml";
declare variable $uri := xdmp:get-request-field("uri");
declare variable $body := xdmp:get-request-body('xml');
xdmp:set-response-encoding("utf-8"),
xdmp:set-response-content-type("application/xml"),
xdmp:log(("data.xqy", xdmp:get-request-method(), $uri, $body)),
if (xdmp:get-request-method() = "GET") then
doc($uri)
else
xdmp:document-insert($uri, $body)
You would also have to change your model to:
<xf:model>
<xf:instance id="data-instance" src="data.xqy?uri=/test/data.xml"
xmlns="" />
<xf:submission id="read-from-file" method="get"
action="data.xqy?uri=/test/data.xml" replace="instance"
instance="data-instance" />
<xf:submission id="save-to-file" method="put"
action="data.xqy?uri=/test/data.xml" replace="instance"
instance="data-instance" />
</xf:model>
You can also look into url rewriting, which will allow you to alter the
behavior of your HTTP app server to handle uri ending on .xml as REST calls,
e.g. have the url rewrite script add ‘data.xqy?uri=’ in front of such urls..
Kind regards,
Geert
Van: [email protected]
[mailto:[email protected]] Namens [email protected]
Verzonden: woensdag 31 augustus 2011 18:13
Aan: General MarkLogic Developer Discussion
Onderwerp: [MarkLogic Dev General] MarkLogic and xsltforms (xf:submission)
I am attempting to use MarkLogic and xsltforms to load data from an xml file
(stored in a MarkLogic database) into the form, edit the data in the form, and
then save the edited xml file back to the MarkLogic database.
I have created the database and the HTTP server. The form correctly reads the
data from the database file ('/test/data.xml') and loads it into the form in
the browser.
The part that does not work is saving the edited file back to the MarkLogic
database (<xf:submission method="put"/>). Can someone explain to me how to
enable the submission? Does it depend on webdav? What are the setup steps?
The xquery is below.
Thanks,
Morgan Cundiff
----------------------------
xquery version "1.0-ml";
declare namespace xdmp="http://marklogic.com/xdmp";
let $page :=
(xdmp:set-response-content-type("application/xml"),
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<title>Submission with get and put</title>
<xf:model>
<xf:instance id="data-instance" src="/test/data.xml" xmlns="" />
<xf:submission id="read-from-file" method="get"
action="/test/data.xml" replace="instance"
instance="data-instance" />
<xf:submission id="save-to-file" method="put"
action="/test/data.xml" replace="instance"
instance="data-instance" />
</xf:model>
</head>
<body>
<p>Demonstration of using XForms to get and put data to ML database using
the submission element.</p>
<xf:input ref="Element1">
<xf:label>Element 1:</xf:label>
</xf:input>
<br />
<xf:input ref="Element2">
<xf:label>Element 2:</xf:label>
</xf:input>
<br />
<xf:input ref="Element3">
<xf:label>Element 3:</xf:label>
<br />
</xf:input>
<xf:submit submission="read-from-file">
<xf:label>Reload</xf:label>
</xf:submit>
<xf:submit submission="save-to-file">
<xf:label>Save</xf:label>
</xf:submit>
</body>
</html>)
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl"
href="xsltforms/xsltforms.xsl"'}
return ($xslt-pi, $page)
-------------------------------------
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general