code: private Attr[] sortAttributes(NamedNodeMap attrs) {
  
          int len = (attrs != null) ? attrs.getLength() : 0;
          Attr[] array = new Attr[len];
          for (int i = 0; i < len; i++) {
              array[i] = (Attr) attrs.item(i);
          }
          for (int i = 0; i < len - 1; i++) {
              String name = array[i].getNodeName();
              int index = i;
              for (int j = i + 1; j < len; j++) {
                  String curName = array[j].getNodeName();
                  if (curName.compareTo(name) < 0) {
                      name = curName;
                      index = j;
                  }
              }
              if (index != i) {
                  Attr temp = array[i];
                  array[i] = array[index];
                  array[index] = temp;
              }
          }
          return (array);
      }
docs: Returns a sorted list of attributes.