Class XmlTreeRenderer

  • All Implemented Interfaces:
    TreeRenderer

    @Experimental
    public final class XmlTreeRenderer
    extends Object
    implements TreeRenderer
    Renders a tree to XML. The resulting document is as close as possible to the representation PMD uses to run XPath queries on nodes. This allows the same XPath queries to match, in theory (it would depend on the XPath engine used I believe).
    • Constructor Detail

      • XmlTreeRenderer

        public XmlTreeRenderer​(XmlTreeRenderer.XmlRenderingConfig strategy)
        Creates a new XML renderer.
        Parameters:
        strategy - Strategy to parameterize the output of this instance
      • XmlTreeRenderer

        public XmlTreeRenderer()
        Creates a new XML renderer with a default configuration.
    • Method Detail

      • renderSubtree

        public void renderSubtree​(Node node,
                                  Appendable out)
                           throws IOException
        Appends the subtree rooted at the given node on the provided output writer. The implementation is free to filter out some nodes from the subtree.

        Each node of the AST has a corresponding XML element, whose name and attributes are the one the node presents in XPath queries.

        Specified by:
        renderSubtree in interface TreeRenderer
        Parameters:
        node - Node to render
        out - Object onto which the output is appended
        Throws:
        IllegalArgumentException - If some node has attributes or a name that is not a valid XML name
        IOException - If an IO error occurs while appending to the output