user299778
user299778

Reputation:

Modify XML node but keep the XML file format intact

How may I modify a XML file without any change like attributes ordering, tag expansion and encoding? (My preference is DOM API)

Upvotes: 7

Views: 4345

Answers (3)

Haroldo_OK
Haroldo_OK

Reputation: 7270

One nice option would be using decentxml. I've successfully used it before for programmatically changing a few attributes of a hand-writen XML config file without losing the formatting. It's not DOM, though.

Upvotes: 2

Vincent Robert
Vincent Robert

Reputation: 36150

You could try VTD-XML.

Since this library builds an index while keeping the file content as-is, its manipulation API will allow to "patch" your file while keeping the rest intact.

Using the VTD-XML API, you will be able to navigate your XML like a DOM tree (even using XPath) and do some modifications (insert elements, insert attributes, etc.)

Upvotes: 7

Tim Jansen
Tim Jansen

Reputation: 3368

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.

Upvotes: 0

Related Questions