code: public String translate(XmlSchema xmlSchema, String avroNamespace,
              String avroSchemaName) throws Xsd2AvroTranslatorException {
  
          log.debug("XML Schema to Avro Schema translator started");
  
          final Map < QName, XmlSchemaElement > items = xmlSchema.getElements();
          ObjectNode rootAvroSchema = null;
  
          final ArrayNode avroFields = MAPPER.createArrayNode();
          if (items.size() > 1) {
              // More then one root, create an aggregate record
              for (Entry < QName, XmlSchemaElement > entry : items.entrySet()) {
                  visit(xmlSchema, entry.getValue(), 1, avroFields);
              }
              rootAvroSchema = buildAvroRecordType(avroSchemaName, avroFields);
  
          } else if (items.size() == 1) {
              XmlSchemaElement xsdElement = (XmlSchemaElement) items.values()
                      .iterator().next();
              if (xsdElement.getSchemaType() instanceof XmlSchemaComplexType) {
                  XmlSchemaComplexType xsdType = (XmlSchemaComplexType) xsdElement
                          .getSchemaType();
                  visit(xmlSchema, xsdType, 1, avroFields);
                  rootAvroSchema = buildAvroRecordType(getAvroTypeName(xsdType),
                          avroFields);
              } else {
                  throw new Xsd2AvroTranslatorException(
                          "XML schema does contain a root element but it is not a complex type");
              }
  
          } else {
              throw new Xsd2AvroTranslatorException(
                      "XML schema does not contain a root element");
          }
          rootAvroSchema.put("namespace", avroNamespace == null ? ""
                  : avroNamespace);
  
          log.debug("XML Schema to Avro Schema translator  ended");
  
          return rootAvroSchema.toString();
      }
docs: Translate the input XML Schema.
  
  @param xmlSchema the input XML Schema
  @param avroNamespace the target Avro namespace
  @param avroSchemaName the target Avro schema name
  @return the Avro schema as a JSON string
  @throws Xsd2AvroTranslatorException if translation fails