code: public void writeFile(Writer writer, boolean contentOnly) throws IOException {
          List<String> namespaces = new ArrayList<>();
          namespaces.add("jcr");
          determineNamespaces(namespaces, contentOnly);
          Collections.sort(namespaces);
          writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
          writer.append("<jcr:root");
          for (int i = 0; i < namespaces.size(); ) {
              String ns = namespaces.get(i);
              String url = NAMESPACES.get(ns);
              if (StringUtils.isNotBlank(url)) {
                  writer.append(" xmlns:").append(ns).append("=\"").append(url).append("\"");
                  if (++i < namespaces.size()) {
                      writer.append("\n         ");
                  }
              } else {
                  i++;
              }
          }
          writeProperty(writer, "        ", "jcr:primaryType", getPrimaryType());
          writeProperties(writer, "        ");
          writer.append(">\n");
          Resource contentResource;
          if ((contentResource = resource.getChild(JcrConstants.JCR_CONTENT)) != null) {
              SourceModel subnodeModel = new SourceModel(config, context, contentResource);
              subnodeModel.writeXml(writer, "    ");
              for (Resource subnode : getSubnodeList()) {
                  String name = subnode.getName();
                  if (!JcrConstants.JCR_CONTENT.equals(name)) {
                      writer.append("    <").append(name).append("/>\n");
                  }
              }
          } else {
              if (!contentOnly) {
                  writeSubnodes(writer, "    ");
              }
          }
          writer.append("</jcr:root>\n");
      }
docs: XML output