private ElementType getElementType(final int pos) {
        ElementType elementType = ElementType.START;
        final StringBuilder sb = new StringBuilder();

        // Find the start bracket.
        int start = -1;
        for (int i = pos; i < arr.length && start == -1; i++) {
            char c = arr[i];
            if (c == '<') {
                start = i;
            }
        }

        // Find the element type.
        boolean inAttValue = false;
        for (int i = start; i < arr.length; i++) {
            char c = arr[i];

            if (!isWhitespace(c)) {
                sb.append(c);
            }

            // Test the element type when we think we are at the end of the
            // element.
            if (c == '"') {
                // Toggle the fact that we are now either in or out of an
                // attribute value.
                inAttValue = !inAttValue;

            } else if (!inAttValue && c == '>') {
                final String element = sb.toString();
                if (element.startsWith(COMMENT_START)) {
                    elementType = ElementType.COMMENT;
                } else if (element.startsWith(PI_START)) {
                    elementType = ElementType.PI;
                } else if (element.startsWith(END_ELEMENT_START)) {
                    elementType = ElementType.END;
                } else if (element.endsWith(EMPTY_ELEMENT_END)) {
                    elementType = ElementType.EMPTY;
                } else if (element.startsWith(DOCTYPE_START)) {
                    elementType = ElementType.DOCTYPE;
                }

                if (elementType == ElementType.COMMENT) {
                    // Don't break out of a comment unless --> is found.
                    if (element.endsWith("-->")) {
                        return elementType;
                    }
                } else {
                    return elementType;
                }
            }
        }

        return elementType;
    }
Determines the type of element that we are entering into.

@return The type of element that we have found.
stroom-core-client-widget/src/main/java/stroom/editor/client/model/XMLStyler.java