Posted By:
guj_alls
Posted On:
Thursday, March 24, 2011 03:49 AM
How to write a program that performs the following task: Given an arbitrary XML document, reverse the order of all elements, pre-serving parent-child relationships. If an element contains more than one XML attribute, the order of these should also be reversed. The program should act as a UNIX filter, taking a UTF-8 encoded XML document on standard input and publishing the reversed document to standard output. Example: $ cat input.xml <?xml version="1.0"?> Hello world Goodbye world Fred & Ginger Test XML document $ cat
More>>
How to write a program that performs the following task:
Given an arbitrary XML document, reverse the order of all elements, pre-serving parent-child relationships. If
an element contains more than one XML attribute, the order of these should also be reversed. The program
should act as a UNIX filter, taking a UTF-8 encoded XML document on standard input and publishing the
reversed document to standard output.
Example:
$ cat input.xml
<?xml version="1.0"?>
Hello world
Goodbye world
Fred & Ginger
Test XML document
$ cat input.xml | java Reverse
<?xml version="1.0"?>
Test XML document
Fred & Ginger
Goodbye world
Hello world
<<Less