private TemplateImpl invokeXmlTemplate(final TemplateToken token,
                                         CustomTemplateCallback callback,
                                         @Nullable ZenCodingGenerator generator,
                                         final boolean hasChildren) {
    ZenCodingGenerator zenCodingGenerator = ObjectUtils.notNull(generator, XmlZenCodingGeneratorImpl.INSTANCE);

    Map<String, String> attributes = token.getAttributes();
    TemplateImpl template = token.getTemplate();
    assert template != null;

    PsiFileFactory fileFactory = PsiFileFactory.getInstance(callback.getProject());
    PsiFile dummyFile = fileFactory.createFileFromText("dummy.html", callback.getFile().getLanguage(), token.getTemplateText(), false, true);
    XmlTag tag = PsiTreeUtil.findChildOfType(dummyFile, XmlTag.class);
    if (tag != null) {
      // autodetect href
      if (EmmetOptions.getInstance().isHrefAutoDetectEnabled() && StringUtil.isNotEmpty(mySurroundedText)) {
        final boolean isEmptyLinkTag = "a".equalsIgnoreCase(tag.getName()) && isEmptyValue(tag.getAttributeValue("href"));
        if (!hasChildren && isEmptyLinkTag) {
          if (HREF_PATTERN.matcher(mySurroundedText).matches()) {
            attributes.put("href", PROTOCOL_PATTERN.matcher(mySurroundedText).find()
                                   ? mySurroundedText.trim()
                                   : "http://" + mySurroundedText.trim());
          }
          else if (EMAIL_PATTERN.matcher(mySurroundedText).matches()) {
            attributes.put("href", "mailto:" + mySurroundedText.trim());
          }
        }
      }

      for (Map.Entry<String, String> attribute : attributes.entrySet()) {
        if (Strings.isEmpty(attribute.getValue())) {
          template.addVariable(prepareVariableName(attribute.getKey()), "", "", true);
        }
      }
      XmlTag tag1 = hasChildren ? expandEmptyTagIfNecessary(tag) : tag;
      setAttributeValues(tag1, attributes, callback, zenCodingGenerator.isHtml(callback));
      token.setTemplateText(tag1.getContainingFile().getText(), callback.getFile());
    }
    template = zenCodingGenerator.generateTemplate(token, hasChildren, callback.getContext());
    removeVariablesWhichHasNoSegment(template);
    return template;
  }
private TemplateImpl invokeXmlTemplate(final TemplateToken token,
                                         CustomTemplateCallback callback,
                                         @Nullable ZenCodingGenerator generator,
                                         final boolean hasChildren)