Java XML Attribute Sort sortAttributes(NamedNodeMap attrs)

Here you can find the source of sortAttributes(NamedNodeMap attrs)

Description

Returns a sorted list of attributes.

License

Open Source License

Parameter

Parameter Description
attrs A map of attributes

Return

A sorted array of attributes

Declaration

protected static Attr[] sortAttributes(NamedNodeMap attrs) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;

import org.w3c.dom.NamedNodeMap;

public class Main {
    /** Returns a sorted list of attributes.
     */*from  w  ww  .ja  va2  s  .com*/
     *  @param attrs A map of attributes
     *  @return A sorted array of attributes 
     */
    protected static 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);
    }
}

Related

  1. sortAttributeNodes(org.w3c.dom.NamedNodeMap attrs)
  2. sortAttributes(NamedNodeMap attrs)
  3. sortAttributes(org.w3c.dom.NamedNodeMap attrs)
  4. sortElementAttributes(NamedNodeMap attrs)