I am extrapolating a little from your original question and your subsequent post, but I think this tutorial *may* point you in the right direction. It was actually written for a completely different purpose, but the way in which I have solved the problem of writing multiple XML files from one dataset, may aid you in an approach for this....
Could you please take a look at talend big data product which provides Spark batch and Streaming feature?
Talend named a Leader.
Kickstart your first data integration and ETL projects.
Watch the recorded webinar!
Pick up some tips and tricks with Context Variables
Learn how media organizations have achieved success with Data Integration
Accelerate your data lake projects with an agile approach