• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to rearrange an xml?

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an xml as below:
<form>
<formfield>
<name>Nikhil_account</name>
<value>12345</value>
</formfield>

<formfield>
<name>Navin_account</name>
<value>2345</value>
</formfield>

<formfield>
<name>Nikhil_balance</name>
<value>125</value>
</formfield>

<formfield>
<name>Navin_balance</name>
<value>89</value>
</formfield>

</form>

Given the above xml how do I rearrange the xml so that it becomes as shown below:

<form>
<formfield>
<name>Nikhil_account</name>
<value>12345</value>
</formfield>

<formfield>
<name>Nikhil_balance</name>
<value>125</value>
</formfield>

<formfield>
<name>Navin_account</name>
<value>2345</value>
</formfield>

<formfield>
<name>Navin_balance</name>
<value>89</value>
</formfield>

</form>
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikhill,
There is probably a much nicer way of doing it, but the simplest approach for me would be to parse the original xml file, extracting the information you require and placing it in a queue ADT like a linked list or similar structure. Then create a new file and write the information from the queue, element by element to the new file.
Hope that helps,

Eoin.
 
Marshal
Posts: 25949
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those two XML documents look identical to me. But maybe they aren't and I just haven't seen the differences.

So instead of just dumping some examples here and asking us to analyze them for you, how about if you do some of the analysis? For example: what is different between the two documents? What are the features of the first document that map into features of the second document? Basic things like that.
 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Paul...maybe if you had gone through the tiny samples of xml that I had 'dumped' then you might have spotted the differences.The difference between the 2 xmls is that the first has the name and value elements of Nikhil's and Navin's account and balance within formfield tags jumbled up whereas the second xml has Nikhil's account and Nikhil's balance one below the other and similarly with Navin's account and balance.And by the way I am on with my own analysis but it is also better to put one's queries on forums like these as this forum is meant for posting ones doubts...I don't think there is any harm in doing so and getting some inputs from the knowledge pool all over the world.A newbie to xml parsing like me would get some foothold with help from here.
[ September 25, 2007: Message edited by: Nikhil Sun ]
 
Paul Clapham
Marshal
Posts: 25949
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at those XML samples carefully, twice, and I didn't see any differences. Now that you point them out, I can see them. Which is why I suggested in my earlier post that you could have explained the difference to start with.

Anyway, I'm glad you are on your way. If you get stuck, then don't hesitate to ask here. With full details, of course, next time.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic