How to get all tab attributes values of all element from .bpmn file?

Hi,
Am new to camunda as well as java.
My requirement is, I want to get all attributes value from all node of every task, event, Gateway… etc through java and transfer to excel file in seperate sheet.

I have tried to code using Read a model document, but cant get exact output.

public class Main {
	public static void main (String[] args) {
		File file = new File("My file path/My_model.bpmn");
		BpmnModelInstance modelInstance = Bpmn.readModelFromFile(file);
		
		// find all elements of the type task
		ModelElementType taskType = modelInstance.getModel().getType(Task.class);
		Collection<ModelElementInstance> taskInstances = modelInstance.getModelElementsByType(taskType);
		
		System.out.println(taskType.getByName());
	}
}

I know it contain nothing much.
Please guide my from the scratch, that how can i achieve my code.

Hi @Junaka and welcome to the Camunda Community!

It looks like you’re printing out the taskTypes by name, but you’re not doing anything with the taskInstance object you got. Have you looked in there to see if that gives you the information you’re looking for?

You’re more than likely going to have to do a fair amount of work to walk the document tree to get all the elements.

Best Regards,
dg

Hi @davidgs…!

Thanks for your answer.
I dont know from where to start.
Can you able to guide me? If possible please post the sample coding for any one task?

Thanks,
Junaka.

Hi @Junaka well, since you have the Collection of taskInstances I’d start by going through that collection to see what kinds of things you’ve got there.

dg

1 Like