void (final XmlBuilder builder, final FlyweightCapableTreeStructure<LighterASTNode> structure, final LighterASTNode doctype) { final Ref<LighterASTNode[]> tokens = new Ref<>(null); final int tokenCount = structure.getChildren(doctype, tokens); if (tokenCount > 0) { CharSequence publicId = null; boolean afterPublic = false; CharSequence systemId = null; boolean afterSystem = false; for (int i = 0; i < tokenCount; i++) { LighterASTNode token = tokens.get()[i]; if (token.getTokenType() == XmlTokenType.XML_DOCTYPE_PUBLIC) { afterPublic = true; } else if (token.getTokenType() == XmlTokenType.XML_DOCTYPE_SYSTEM) { afterSystem = true; } else if (token.getTokenType() != TokenType.WHITE_SPACE && token.getTokenType() != XmlElementType.XML_COMMENT) { if (token.getTokenType() == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) { if (afterPublic) publicId = getTokenText(token); else if (afterSystem) systemId = getTokenText(token); } afterPublic = afterSystem = false; } } builder.doctype(publicId, systemId, doctype.getStartOffset(), doctype.getEndOffset()); } }