You can use following package to achieve this
FOR CQ5.3 and CQ5.4
FOR CQ5.6 (Also fixes some other issues)
Above package might not work for AEM 6 onward because of this feature You might have to do disable POST from felix console for CSRF token. Add it back after running this tool.
1) Download and Install package using package manager
2) go to <host>:<port>/apps/tools/components/createPackage/run.html
3) Give your Xpath in xpath value
4) You can also add comma separate exclude path that you don't want to add to package.
5) Click on Create config package
6) Now Download the package and also be saved under /etc/packages/CQSupportTool
For example if you have to create package of all ACL to migrate from one CQ instance to another you can use xpath query for package as //element(*,rep:ACL)
Please note that, this package is for test purpose only. Feel free to modify it based on your need.
Known Issue Exception when "/" root is given (I will fix that as soon as get some time).