Browse a document

I have a document like that :
Document
SubDocument (Name = Header)
Var1
Var2
SubDocument (Name = Body)
Bd1
Bd2

Bdn

I want to create a service which create this document :
DocumentOut
Var1
Var2
Bd1
Bd2

Bdn.

Like this, that seems easy.
The problem is I have a generic Document in Input. The name of document is not the same for each invoke. The name of header sub document is the same but not the name of body subdocument (neither the variables and name of variables).

So I would like to create a JavaService whick make the job.
If I know to get a Document with the interface IData and the static method IDataUtil.GetIData, I don’t know how to browse the subdocument and test the name of this subdocument (if eq to “header” or not equal to “header”).

Thans to help me by advance.

Can you please share document screenshot for better understanding?