private void nodeToStringBuffer(Node node, StringBuffer buffer, int indent) {
        if (indent >= 0) {
            if (indent > 0) {
                buffer.append("\n");
            }
            buffer.append(StringUtil.repeat(" ", indent));
        }
        buffer.append("<").append(node.getNodeName());
        SortedMap<String, String> attributeMap = new TreeMap<>();
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            attributeMap.put(attribute.getNodeName(), attribute.getNodeValue());
        }
        boolean firstAttribute = true;
        for (Map.Entry entry : attributeMap.entrySet()) {
            String value = (String) entry.getValue();
            if (value != null) {
                if ((indent >= 0) && !firstAttribute && (attributeMap.size() > 2)) {
                    buffer.append("\n").append(StringUtil.repeat(" ", indent)).append("        ");
                } else {
                    buffer.append(" ");
                }
                buffer.append(entry.getKey()).append("=\"").append(value).append("\"");
                firstAttribute = false;
            }
        }
        String textContent = StringUtil.trimToEmpty(XMLUtil.getTextContent(node));
        buffer.append(">").append(textContent);

        boolean sawChildren = false;
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode instanceof Element) {
                int newIndent = indent;
                if (newIndent >= 0) {
                    newIndent += 4;
                }
                nodeToStringBuffer(childNode, buffer, newIndent);
                sawChildren = true;
            }
        }
        if (indent >= 0) {
            if (sawChildren) {
                buffer.append("\n").append(StringUtil.repeat(" ", indent));
            }
        }

        if (!sawChildren && "".equals(textContent)) {
            buffer.replace(buffer.length() - 1, buffer.length(), "/>");
        } else {
            buffer.append("</").append(node.getNodeName()).append(">");
        }
    }
private void nodeToStringBuffer(Node node, StringBuffer buffer, int indent) {
        if (indent >= 0) {
            if (indent > 0) {
                buffer.append("\n");
            }
            buffer.append(StringUtil.repeat(" ", indent));
        }
        buffer.append("<").append(node.getNodeName());
        SortedMap<String, String> attributeMap = new TreeMap<>();
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            attributeMap.put(attribute.getNodeName(), attribute.getNodeValue());
        }
        boolean firstAttribute = true;
        for (Map.Entry entry : attributeMap.entrySet()) {
            String value = (String) entry.getValue();
            if (value != null) {
                if ((indent >= 0) && !firstAttribute && (attributeMap.size() > 2)) {
                    buffer.append("\n").append(StringUtil.repeat(" ", indent)).append("        ");
                } else {
                    buffer.append(" ");
                }
                buffer.append(entry.getKey()).append("=\"").append(value).append("\"");
                firstAttribute = false;
            }
        }
        String textContent = StringUtil.trimToEmpty(XMLUtil.getTextContent(node));
        buffer.append(">").append(textContent);

        boolean sawChildren = false;
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode instanceof Element) {
                int newIndent = indent;
                if (newIndent >= 0) {
                    newIndent += 4;
                }
                nodeToStringBuffer(childNode, buffer, newIndent);
                sawChildren = true;
            }
        }
        if (indent >= 0) {
            if (sawChildren) {
                buffer.append("\n").append(StringUtil.repeat(" ", indent));
            }
        }

        if (!sawChildren && "".equals(textContent)) {
            buffer.replace(buffer.length() - 1, buffer.length(), "/>");
        } else {
            buffer.append("</").append(node.getNodeName()).append(">");
        }
    }
private void nodeToStringBuffer ( Node node , StringBuffer buffer , int indent ) { if ( indent >= 0 ) { if ( indent > 0 ) { buffer . append ( "\n" ) ; } buffer . append ( StringUtil . repeat ( " " , indent ) ) ; } buffer . append ( "<" ) . append ( node . getNodeName ( ) ) ; SortedMap < String , String > attributeMap = new TreeMap <> ( ) ; NamedNodeMap attributes = node . getAttributes ( ) ; for ( int i = 0 ; i < attributes . getLength ( ) ; i ++ ) { Node attribute = attributes . item ( i ) ; attributeMap . put ( attribute . getNodeName ( ) , attribute . getNodeValue ( ) ) ; } boolean firstAttribute = true ; for ( Map . Entry entry : attributeMap . entrySet ( ) ) { String value = ( String ) entry . getValue ( ) ; if ( value != null ) { if ( ( indent >= 0 ) && ! firstAttribute && ( attributeMap . size ( ) > 2 ) ) { buffer . append ( "\n" ) . append ( StringUtil . repeat ( " " , indent ) ) . append ( "        " ) ; } else { buffer . append ( " " ) ; } buffer . append ( entry . getKey ( ) ) . append ( "=\"" ) . append ( value ) . append ( "\"" ) ; firstAttribute = false ; } } String textContent = StringUtil . trimToEmpty ( XMLUtil . getTextContent ( node ) ) ; buffer . append ( ">" ) . append ( textContent ) ; boolean sawChildren = false ; NodeList childNodes = node . getChildNodes ( ) ; for ( int i = 0 ; i < childNodes . getLength ( ) ; i ++ ) { Node childNode = childNodes . item ( i ) ; if ( childNode instanceof Element ) { int newIndent = indent ; if ( newIndent >= 0 ) { newIndent += 4 ; } nodeToStringBuffer ( childNode , buffer , newIndent ) ; sawChildren = true ; } } if ( indent >= 0 ) { if ( sawChildren ) { buffer . append ( "\n" ) . append ( StringUtil . repeat ( " " , indent ) ) ; } } if ( ! sawChildren && "" . equals ( textContent ) ) { buffer . replace ( buffer . length ( ) - 1 , buffer . length ( ) , "/>" ) ; } else { buffer . append ( "</" ) . append ( node . getNodeName ( ) ) . append ( ">" ) ; } }
/*
Creates a {@link String} using the XML element representation of this
change

@param node the {@link Element} associated to this change
@param buffer a {@link StringBuffer} object used to hold the {@link String}
representation of the change
/ * Creates a { @link String } using the XML element representation of this change