I am constructing XML code using Java. See my code snippet.
    Document document = null;
    String xml = "";
    ReportsDAO objReportsDAO = null;
    try 
    {
        logger.info("Getting XML data for Consumable Report Starts...");
        objReportsDAO = new ReportsDAO();
        List consumableDTOLst = objReportsDAO.getConsumableData(issuedBy, issuedTo, employeeType, itemCode, itemName, className, transactionFromDate, transactionToDate, machineCode, workOrderNumber, jobName, customerId);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
        Element rootElmnt = (Element) document.createElement("items");  
        document.appendChild(rootElmnt);
        Element elmt = null;
        ConsumableDTO objConsumableDTO = null;
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        for (int i = 0; i < consumableDTOLst.size(); i++) 
        {
            objConsumableDTO = (ConsumableDTO)consumableDTOLst.get(i);
            elmt =  (Element) document.createElement("item");
            elmt.setAttribute("IssuedBy", objConsumableDTO.getIssuedBy());
            elmt.setAttribute("IssuedTo", objConsumableDTO.getIssuedTo());
            elmt.setAttribute("EMPLOYECADRE", objConsumableDTO.getEmployeeType());
            elmt.setAttribute("ITEMCODE", objConsumableDTO.getItemCode());
            elmt.setAttribute("ITEMNAME", objConsumableDTO.getItemName());
            elmt.setAttribute("ITEMCLASS", objConsumableDTO.getClassName());
            elmt.setAttribute("DATE", sdf.format(objConsumableDTO.getTransactionDate()));
            elmt.setAttribute("machineCode", objConsumableDTO.getMachineCode());
            elmt.setAttribute("JOB", objConsumableDTO.getJobName());
            elmt.setAttribute("WORKORDERNUMBER", objConsumableDTO.getWorkOrderNumber());
            elmt.setAttribute("CustomerName", objConsumableDTO.getCustomerName());
            elmt.setAttribute("RoleName", objConsumableDTO.getGroupName());
            elmt.setAttribute("VendorName", objConsumableDTO.getVendorName());
            elmt.setAttribute("QTY", String.valueOf(Math.abs(objConsumableDTO.getQuantity())));
            elmt.setAttribute("unitDescription", objConsumableDTO.getUnitDescription());
            elmt.setAttribute("RATEPERQTY", String.valueOf(objConsumableDTO.getRate()));
            elmt.setAttribute("AMOUNT", String.valueOf(objConsumableDTO.getAmount()));
            rootElmnt.appendChild(elmt);
        }
The problem is all the attributes are sorted automatically. How to restrict it?
For eg,
<empdetails age="25" name="john"/>
but i want
<empdetails name="john" age="25"/>
Please suggest some idea.
Thanks,