Code taken from and slightly modified: svn r133, git 71e2a7fd3675ddb5f57f9d4c9aecec204b984e6b Implemented RequireClosingTag flag for custom-defined elements