private static final String nextXMLFragment(final Reader reader, final boolean ignoreWhitespace)
            throws IOException {
        final StringBuilder builder = new StringBuilder();
        boolean inElement = false;
        boolean inAttribute = false;
        boolean inQuotes = false;

        final List<String> attributes = new ArrayList<>();
        final StringBuilder attribute = new StringBuilder();

        while (true) {
            final int i = nextChar(reader, ignoreWhitespace);
            if (i == -1) {
                return builder.toString();
            }

            final char c = (char) i;
            if (!inQuotes && c == '<') {
                inElement = true;
                inAttribute = false;
            }
            if (inAttribute && c == '\"') {
                inQuotes = !inQuotes;
            }
            if (!inQuotes && (c == '>' || c == '/')) {
                inElement = false;
                inAttribute = false;
                inQuotes = false;

                if (attribute.length() > 0) {
                    attributes.add(attribute.toString());
                    attribute.setLength(0);
                }
                Collections.sort(attributes);
                for (final String att : attributes) {
                    builder.append(" ");
                    builder.append(att);
                }
                attributes.clear();
                builder.append(c);
                return builder.toString();
            }
            if (inElement) {
                if (isCharNothing(c)) {
                    inAttribute = true;
                }
                if (!inAttribute) {
                    builder.append(c);
                } else {
                    if (isCharNothing(c)) {
                        if (attribute.length() > 0) {
                            attributes.add(attribute.toString());
                            attribute.setLength(0);
                        }
                    } else {
                        attribute.append(c);
                    }
                }
            } else {
                builder.append(c);
            }
        }
    }
Generate a unified diff of the two files using the specified number of lines of context.
The diff output is sent to system out in coloured form.

@return True if the files are the same
stroom-test-common/src/main/java/stroom/test/common/ComparisonHelper.java