Skip to content

XML Document Inversion

Write a program, preferably in Java (Python is also acceptable), that reads an XML file from disk, inverts parent-child element relationships and prints the result to the standard output (System.out). For example, passing the following XML as input to your program:

<a>
  <b>
    <c/>
  </b>
</a>  

should produce the output below:

<c>
  <b>
    <a/>
  </b>
</c>

Libraries

You are allowed (and strongly encouraged) to use existing built-in/open-source libraries to parse XML documents instead of developing your own XML parser.