How to dump an XDOM structure to text?
Version 2.1 by Vincent Massol on 2017/12/19
See Rendering Arhictecture to know more about what is an XDOM.
From Velocity:
{{velocity}}
#set ($xdom = $services.rendering.parse('hello world', 'xwiki/2.1'))
{{code}}
$services.rendering.render($xdom, 'event/1.0')
{{/code}}
{{/velocity}}
#set ($xdom = $services.rendering.parse('hello world', 'xwiki/2.1'))
{{code}}
$services.rendering.render($xdom, 'event/1.0')
{{/code}}
{{/velocity}}
Generates:
beginDocument [[syntax]=[XWiki 2.1]]
beginParagraph
onWord [hello]
onSpace
onWord [world]
endParagraph
endDocument [[syntax]=[XWiki 2.1]]
beginParagraph
onWord [hello]
onSpace
onWord [world]
endParagraph
endDocument [[syntax]=[XWiki 2.1]]
From Groovy:
{{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()
{{/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()
{{/groovy}}
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.