I have this XML file
<Source>
<segment1>
<userRefNumber>test1</userRefNumber>
<subscriber>
<industryCode>ZZZZZ</industryCode>
<memberCode>12345</memberCode>
<inquirySubscriberPrefixCode>0622</inquirySubscriberPrefixCode>
</subscriber>
<options>
<country>us</country>
<language>en</language>
</options>
<tracking>
<transactionTimeStamp>2021-02-25T04:09:30.508-06:00</transactionTimeStamp>
</tracking>
</segment1>
<example2>
<subscriber>
<industryCode>ZAAAA</industryCode>
<memberCode>999999</memberCode>
<inquirySubscriberPrefixCode>0622</inquirySubscriberPrefixCode>
</subscriber>
<options>
<country>us</country>
<language>en</language>
</options>
<tracking>
<transactionTimeStamp>2020-02-25T04:09:30.508-06:00</transactionTimeStamp>
</tracking>
</example2>
</Source>
I'd like to create, through Python, two XML files, that is one for each child:
- one xml file for segment1
- one xml file for segment2
xml1 should look like this:
<Source>
<segment1>
<userRefNumber>test1</userRefNumber>
<subscriber>
<industryCode>ZZZZZ</industryCode>
<memberCode>12345</memberCode>
<inquirySubscriberPrefixCode>0622</inquirySubscriberPrefixCode>
</subscriber>
<options>
<country>us</country>
<language>en</language>
</options>
<tracking>
<transactionTimeStamp>2021-02-25T04:09:30.508-06:00</transactionTimeStamp>
</tracking>
</segment1>
</Source>
and xml2 should look like this:
<Source>
<example2>
<subscriber>
<industryCode>ZAAAA</industryCode>
<memberCode>999999</memberCode>
<inquirySubscriberPrefixCode>0622</inquirySubscriberPrefixCode>
</subscriber>
<options>
<country>us</country>
<language>en</language>
</options>
<tracking>
<transactionTimeStamp>2020-02-25T04:09:30.508-06:00</transactionTimeStamp>
</tracking>
</example2>
</Source>
The splitting criteria is this: to create one separate xml file for each element. In the example above there are two elements (segment1 and example2): therefore i'd like to create two xml files for each one of those.
I have checked this answer Split one large .xml file in more .xml files (python) but in that example the children have the same name so I guess the findall function doesn't apply to my case, as the children have different names (segment1 and segment2). Is it possible to create a single xml file based on the order of the elements from the root?