0

I have used DOMsorce for XML modification when i am writing modified data to a new file it is changing actual order of attributes(ascending order). so how to control this modification.

saravankg
  • 909
  • 1
  • 10
  • 21

1 Answers1

0

I have a quite similar problem. I need to have always the same attribute for first. Example :

<h50row a="1" xidx="1" c="1"></h50row>
<h50row a="2" b="2" xidx="2"></h50row>

must become

<h50row xidx="1" a="1" c="1"></h50row>
<h50row xidx="2" a="2" b="2"></h50row>

I found a solution with a regex:

test = "<h50row a=\"1\" xidx=\"1\" c=\"1\"></h50row>";
test = test.replaceAll("(<h5.*row)(.*)(.xidx=\"\\w*\")([^>]*)(>)", "$1$3$2$4$5");

Hope you find this usefull