I'm trying to replace values of some attributes in an SVG file using StAX iterator API. I read an original file using XMLEventReader, checking and modifying elements, and then writing into XMLEventWriter.
My original file has the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<!--
...
-->
<!DOCTYPE ...
...
]>
<svg ...
The output I get is not the same:
<?xml version="1.0"?><!--
...
--><!DOCTYPE ...
...
]><svg ...
As you can see, encoding is gone, as well as newlines around a comment and doctype.
Also, order of all attributes on all tags in the resulting file seems to be random. I've read another question and I'm aware that attribute order is not guaranteed, but this doesn't help me.
These SVG files are under Git, so I'd like to preserve their plain-text layout as much as possible.
How do I fix those issues? With my current task, I could just replace attribute values as plain text, without any parsing, but I would like to have a solution which would allow me to take tag nesting and things like that into account.
If it can't be done with StAX, I'm totally open to different approaches. I've already tried DOM approach, and it's even worse. Maybe there are some 3d-party parsers...
Aucun commentaire:
Enregistrer un commentaire