How to convert Confluence Storage Format XML to HTML?

confluence storage markup
confluence xml
confluence document format
atlassian storage format
confluence rest api storage format
confluence specific xml
ac:link confluence
confluence updatepage

I am pulling content from confluence using the REST API.

https://docs.atlassian.com/atlassian-confluence/REST/3.2/

The API returns confluence pages with a content property. The content is a mix of XHTML and proprietary XML tags. The XML is Confluence Storage Format:

https://confluence.atlassian.com/display/DOC/Confluence+Storage+Format

The custom XML tags are used for things like images, relative links, and attachments. If I render the content straight out the custom XML will not render.

I've found what looks like an endpoint that is supposed to convert the the format: https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/xhtml/api/XhtmlContent.html

I don't think it is longer supported.

I've also found this project:

http://www.amnet.net.au/~ghannington/confluence/readme.html#wikifier

Which converts confluence XML into confluence wiki markup. The project comes with two .xsl sheets One sheet is confluence2wiki.xsl which handles the markup conversion, and the other is confluence2xhtml.xslwhich sounds like it would do the job but unfortunately the implementation is poor. It literally converts the confluence XML into XHTML that looks like the XML. So an image tag from the confluence XML unfortunately becomes:

<div class="extension-element">
  <p class="extension-element-markup">
    <span class="element-name">ac:image</span>
    <span class="attribute-name">ac:alt</span>
    <span class="markup">="</span>
    <span class="attribute-value">Example1.png</span>
    <span class="markup">"</span>
  </p>
  <div class="extension-element-contents">
    <div class="extension-element">
      <p class="extension-element-markup">
        <span class="element-name">ri:url</span>
        <span class="attribute-name">ri:value</span>
        <span class="markup">="</span>
        <span class="attribute-value">https://example.com/attachments/token/2ujwb0dm4jsorgk/?name=Omniata_Docs_Projects_Example1.png</span>
        <span class="markup">"</span>
      </p>
    </div>
  </div>
</div>

Call the renderContent method via Remote API. There's also a convertWikiToStorageFormat method if your content is in older format.

How to convert Confluence Storage Format XML to HTML? - xml, The XML is Confluence Storage Format: https://confluence.atlassian.com/display/ DOC/Confluence+Storage+Format The custom XML tags are used for things� To be correct, we should call it XML, because the Confluence storage format does not comply with the XHTML definition. In particular, Confluence includes custom elements for macros and more. We're using the term 'XHTML-based' to indicate that there is a large proportion of HTML in the storage format.


If you need to do this, using a REST API, currently the best way would be to write a plugin and implement your own REST API that does the conversion for you.

Something like this should start you on your way by converting the storage format into HTML:

public String convertStorageToView(int pageId)
{
    Page page = pageManager.getById(pageId);        
    String storage = page.getBodyAsString();

    try
    {
        final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext());

        return xhtmlContent.convertStorageToView(storage, conversionContext);
    }
    catch (XhtmlException e)
    {
        e.printStackTrace();
    }
    catch (XMLStreamException e)
    {
        e.printStackTrace();
    }

    return null;
}

You'll also have to write the REST module.

Confluence Storage Format, The rich text editor HTML and the elements in the Confluence storage format that have the same names as XHTML elements are similar. The big� To be correct, we should call it XML, because the Confluence storage format does not comply with the XHTML definition. In particular, Confluence includes custom elements for macros and more. We're using the term 'XHTML-based' to indicate that there is a large proportion of HTML in the storage format.


Similar like it was already shown in an other answer, but for me it was not clear that you have to use the xhtmlContent. You can easily get an instance of that via the constructor.

public class MyServlet extends HttpServlet {

    private Logger LOGGER = Logger.getLogger(getClass());

    private final PageManager pageManager;
    private final XhtmlContent xhtmlContent;


    public static final String PARAM_PAGE_ID = "pageId";


    public MyServlet( PageManager pageManager, XhtmlContent xhtmlContent) {
    this.pageManager = pageManager;
        this.xhtmlContent = xhtmlContent;
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        //fetch page or blogpost
        ContentEntityObject page = pageManager.getPage(Long.parseLong(request.getParameter(PARAM_PAGE_ID)));
        if (page == null) {
            page = pageManager.getBlogPost(Long.parseLong(request.getParameter(PARAM_PAGE_ID)));
        }
        if (page != null) {
            String htmlContent = "";
            final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext());
            try {
                htmlContent = xhtmlContent.convertStorageToView(page.getBodyAsString(), conversionContext);
            } catch (XMLStreamException e) {
                htmlContent = "ERROR ON EXPORT";
                LOGGER.error(e);
            } catch (XhtmlException e) {
                htmlContent = "ERROR ON EXPORT";
                LOGGER.error(e);
            }

        } else {
        //do some errorhandling here
    }
    //.. do something with the content .. render it in a velocity file for example
    }

You can render the data in a velocity file for example or write it direct in the response.

How to convert Confluence XML storage format to wiki markup , confluence2xhtml.xsl, XSLT stylesheet: transforms Confluence storage format into If Wikifier does not correctly convert some Confluence XML, please let me know, (or even, say, as the contents of the existing Confluence 3 HTML macro). The HTML export is useful if you want convert your space into a static website, and the XML export option works if you need to import the space into another Confluence site or use the data from the space in another application. You can use the PDF option if you're producing a user manual from your technical documentation in Confluence.


XML schema for the Confluence storage format, This page is an extension of the page about the Confluence storage format. [ Anchor macro ] [ Attachments macro ] [ Blog Posts macro ] [ Change-History macro ] [ Chart ac:name="language">html/xml</ac:parameter> <ac:plain-text- body><! Export files are also XML, and contain pages represented in Confluence storage format, but the rest of the export file XML is not deemed to be “Confluence storage format”. That link should clarify these issues for you; if not, feel free to email me, add another reply here, or send a carrier pigeon.


Confluence Storage Format for Macros, Publish DITA to Microsoft Word and import in Confluence The internal storage format Confluence uses is a kind of HTML mixed with XML� An XML W3C Schema 1.0 document (XSD) for the Confluence storage format (actually, a set of XSDs: one for each namespace) An XML document type definition (DTD) for the Confluence storage format; Various related sample files (including the source for Wikifier, a web-based "Confluence XML to wiki markup" converter)


DITA to Confluence - Oxygen XML Blog, Sometimes you might want to create a confluence page corresponding to an issue. For instance when new Epic types are created, or when high-priority issues change state. Here is a full example of using the storage format to create the page: storage format using an XML builder def writer = new StringWriter() def xml� Confluence stores content in what they call Confluence storage format - it is 'XHTML-based', but not pure XML or normal HTML, as it contains special tags related to Confluence functionality. Some of the issues could be CSS related too, particularly for text alignments and tabs.