How to dump an XDOM structure to text?

Last modified by Vincent Massol on 2017/12/20

See Rendering Arhictecture to know more about what is an XDOM.

From Velocity:

#set ($xdom = $services.rendering.parse('hello world', 'xwiki/2.1'))
$services.rendering.render($xdom, 'event/1.0')


beginDocument [[syntax]=[XWiki 2.1]]
onWord [hello]
onWord [world]
endDocument [[syntax]=[XWiki 2.1]]

From Groovy:

import org.xwiki.rendering.renderer.printer.*

def xdom = services.component.getInstance(org.xwiki.rendering.parser.Parser.class, 'xwiki/2.1').parse(new StringReader('hello world'))
def renderer = services.component.getInstance(org.xwiki.rendering.renderer.BlockRenderer.class, 'event/1.0')

def printer = new DefaultWikiPrinter()
renderer.render(xdom, printer)
out.println printer.toString()

Note that the event/1.0 syntax is not bundled by default in XWiki/ You can install it in your wiki using the Extension Manager by using advanced search using the extension id org.xwiki.rendering:xwiki-rendering-syntax-event.

Once you've installed the event/1.0 syntax you can also view all the events for the current page by manually adding the following to the XWiki URL: ?outputSyntax=event and replace the view action by the get one. For example: http://localhost:8080/xwiki/bin/get/Sandbox/?outputSyntax=event



Get Connected