package com.srbenoit.xml;

/**
 * A CDATA node, used to represent any characters that are not part of tags. Whitespace is retained
 * in these nodes exactly as supplied in the source XML.
 */
public class CData implements Node {

    /** the start position of the block */
    public final transient int start;

    /** the end position of the block */
    public final transient int end;

    /**
     * Constructs a new <code>CData</code>.
     *
     * @param  startPos  the start position of the block
     * @param  endPos    the end position of the block
     */
    public CData(final int startPos, final int endPos) {

        this.start = startPos;
        this.end = endPos;
    }

    /**
     * Generates the print representation of the node (may recursively call this method on child
     * nodes).
     *
     * @param   xml  the source XML
     * @return  the print representation
     */
    public String print(final String xml) {

        return xml.substring(this.start, this.end);
    }
}
