How may I modify a XML file without any change like attributes ordering, tag expansion and encoding? (My preference is DOM API)
This is not possible with DOM, since DOM does not know the attributes' order.
You could use a low-level API such as StAX, javax.xml.stream, but StAX is not exactly comfortable to use.