Here you can find the source of sortAttributes(org.w3c.dom.NamedNodeMap attrs)
public static org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
//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); } }