2
votes

i was looking for a way to expand XML nodes using marklogic java client api, but wasnt able to find any information on this topic from api documentation.

sample xquery that expands xinclude nodes:

import module namespace xinc = "http://marklogic.com/xinclude" at "/MarkLogic/xinclude/xinclude.xqy";
xinc:node-expand(fn:doc("http://my.app.org/contact/234"))

is it possible to do "node-expand" when reading document from marklogic database using java client api XMLDocumentManager.read("http://my.app.org/contact/234") ?

sample document:

<contact>
    <photo>
        <xi:include href="http://my.app.org/files/123" xpointer="xpath(//file/content/text())" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
    </photo>
</contact>

Thanks!

1

1 Answers

3
votes

One way might be to create a transformation named expandXInclude.xqy and use this while reading.

XMLDocumentManager.read("http://my.app.org/contact/234", new DOMHandle(), new ServerTransform("expandXInclude.xqy"));

Transformations can be created and deployed with ml-gradle. See a basic example here. The transformation might be as simple as this:

xquery version "1.0-ml";

module namespace transform = "http://marklogic.com/rest-api/transform/sample";
import module namespace xinc = "http://marklogic.com/xinclude" at "/MarkLogic/xinclude/xinclude.xqy";

declare function transform(
        $context as map:map,
        $params as map:map,
        $content as document-node()
) as document-node()
{
    xinc:node-expand($content)
};