That is a very complex task. In case you really want to go that route, I would save config, and then work on export.xml from a Domain .zip export. You would need to parse all objects, and for those based on others you need to mark all its sub objects as "used". Most difficult part is that some objects are referenced by (string) name.
A better approach would be to save and export a domain. Then delete domain, and create it freshly. Finally import only the onjects you are interested from the export -- objects needed should be pulled in automatically.
#DataPower#Support#SupportMigration