Java - parse nested xml file and write to the file

Viewed 557

I have a .xml file like below:

    <?xml version="1.0"?>
    <Event>
    <Issue>ggg</Issue>
    <City>Athen</City>   
      <Group>
      <AlternateIdentification>
        <AlternateID>DG800</AlternateID>
        <AlternateIDType>GoA</AlternateIDType>
      </AlternateIdentification>
      <AlternateIdentification>
        <AlternateID>SS500</AlternateID>
        <AlternateIDType>SDD</AlternateIDType>
      </AlternateIdentification>
      <AlternateIdentification>
        <AlternateID>TY158</AlternateID>
        <AlternateIDType>YTU</AlternateIDType>
      </AlternateIdentification>
      </Group>
    </Event>

And I would like to parse .xml file and write the output to the flat .txt file with lines like this:

ggg Athen DG800
ggg Athen SS500
ggg Athen TY158

Can you help me and tell me how to do this with javax DOM parser? I have no idea how to start :( This common part confuses me the most because I need to iterate this file in this case 3 times to get 3x "ggg Athen" and then additional tag AlternateID?

2 Answers
Related