Splitting XML file into multiple at given tags

Viewed 27686

I want to split a XML file into multiple files. My workstation is very limited to Eclipse Mars with Xalan 2.7.1.

I can also use Python, but never used it before.

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <row>
        <NAME>Doe</NAME>
        <FIRSTNAME>Jon</FIRSTNAME>
        <GENDER>M</GENDER>
    </row>
    <row>
        <NAME>Mustermann</NAME>
        <FIRSTNAME>Max</FIRSTNAME>
        <GENDER>M</GENDER>
    </row>
</root>

How can I transform them to look like this

<?xml version="1.0" encoding="UTF-8"?>
    <root>
        <row>
            <NAME>Doe</NAME>
            <FIRSTNAME>Jon</FIRSTNAME>
            <GENDER>M</GENDER>
        </row>
    </root>

I need every "row"-data in a single file with header. The data above is just an example. Most of the "row"-data has 16 attributes, but it varies from time to time.

3 Answers
Related