Hi,
Do you specifically need to code it yourself? To this this quickly and repeatedly one can easily use a tool called Linx 5 without having to code. You can read the XML into the tool and get the whole data structure, which you can then write into any database you'd like (SQL, MySQL, Oracle, etc.).
You can check it out at
Linx 5 - Welcome[
^]