Java XML Attribute Sort sortAttributes(org.w3c.dom.NamedNodeMap attrs)

Here you can find the source of sortAttributes(org.w3c.dom.NamedNodeMap attrs)

Description

sort Attributes

License

Open Source License

Declaration

public static org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   w w  w .  j a  v  a  2s.c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs) {
        int len = (attrs != null) ? attrs.getLength() : 0;
        org.w3c.dom.Attr array[] = new org.w3c.dom.Attr[len];
        for (int i = 0; i < len; i++) {
            array[i] = (org.w3c.dom.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) {
                org.w3c.dom.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(NamedNodeMap attrs)
  4. sortElementAttributes(NamedNodeMap attrs)