I have the following code: element.clear(); element.setTagName("accountpoint"); element.setAttribute("code", QString(ID_CONST)+serial); element.setAttribute("name", QString()); element.setAttribute("serial", serial); QFile file(filename); file.open(QIODevice::ReadWrite); QTextStream stream(&file); doc.save(stream, 4); I thought I will get an XML like: <accountpoint code="4871583314750580" name="" serial="14750580"> But I have: <accountpoint serial="14750580" code="4871583314750580" name=""> Why? P.S. Yes, of course, in XML document it does not matter, but I want to get the right order of