code: public final static int readXML(final StringBuilder out, final String in, final int start, final boolean safeMode)
      {
          int pos;
          final boolean isCloseTag;
          try
          {
              if (in.charAt(start + 1) == '/')
              {
                  isCloseTag = true;
                  pos = start + 2;
              }
              else if (in.charAt(start + 1) == '!')
              {
                  out.append("<!");
                  return start + 1;
              }
              else
              {
                  isCloseTag = false;
                  pos = start + 1;
              }
              if (safeMode)
              {
                  final StringBuilder temp = new StringBuilder();
                  pos = readXMLUntil(temp, in, pos, ' ', '/', '>');
                  if (pos == -1)
                  {
                      return -1;
                  }
                  final String tag = temp.toString().trim().toLowerCase();
                  if (HTML.isUnsafeHtmlElement(tag))
                  {
                      out.append("&lt;");
                  }
                  else
                  {
                      out.append("<");
                  }
                  if (isCloseTag)
                  {
                      out.append('/');
                  }
                  out.append(temp);
              }
              else
              {
                  out.append('<');
                  if (isCloseTag)
                  {
                      out.append('/');
                  }
                  pos = readXMLUntil(out, in, pos, ' ', '/', '>');
              }
              if (pos == -1)
              {
                  return -1;
              }
              pos = readXMLUntil(out, in, pos, '/', '>');
              if (in.charAt(pos) == '/')
              {
                  out.append(" /");
                  pos = readXMLUntil(out, in, pos + 1, '>');
                  if (pos == -1)
                  {
                      return -1;
                  }
              }
              if (in.charAt(pos) == '>')
              {
                  out.append('>');
                  return pos;
              }
          }
          catch (final StringIndexOutOfBoundsException e)
          {
              return -1;
          }
          return -1;
      }
docs: Reads an XML element.
  
  @param out
  The StringBuilder to write to.
  @param in
  Input String.
  @param start
  Starting position.
  @param safeMode
  Whether to escape unsafe HTML tags or not
  @return The new position or -1 if this is no valid XML element.