Please
UseCodeTags and punctuation. If I understand you correctly then you want to write the values from a xml-file to a database. Can't you just insert all the tables first and then add the relations? If not and the constraints are not ordered then you'll need to build a data-structure that houses the constraints and let's you extract the proper order of inserting them.