Here's a DTD I have but I've been having some trouble parsing it and generating a hash in Perl from it. I want to parse a xml document with the below layout and end up having a hash with the data stored. The xml document is essentially a tree of data, some branches longer than others and varying number of child nodes.

The end hash should consist of a hash hierarchy of only the values from the "id" elements. blockInfo contains information about the current treeTop item. So a treeTop item has an id instead of blockInfo that is unique and a treeTop item can contain more treeTop items, or in this case I guess you can call branches.

I'm using XML::Simple. I need an algorithm that will end up with a hash made up of only "id" values from the xml document so I need to parse it. Some "treeTop"s may have no treeTop tags under it, one treeTop tag, or many.

But that's my question. I want to know how to go through the hash level by level and create the hash. If I only go 2 levels it's fine but somehow I'm losing levels as I go farther down. I think it's cause I'm overwriting levels when I come back. I make a recursive call to the same routine to handle the next branch in the tree. I'm wondering what I need to do to recursively call a routine and have it parse and generate the hash I need.

Hmm.... maybe I should ask this. If I know I'll need to start setting values (let's say 3 levels into a hash) but the second level isn't set (doesn't exist) what's the best way to "initialize" it? So if I try to set $hash{"level1"}{"level2"}{"level3"} without "level2" existing should I set it to something? Right now I do a check to see if it exists and then do $hash{"level1"}{"level2"} = {} but I end up getting a "" entry in the hash that I don't want. I think this is where my code is mixed up a bit. I've moved too much around trying things out to post right now but if someone could give me some feedback on how to initialize a level not created in a case like above I'd appreciate it. If it doesn't work out I'll get the code back to initial state and post the subroutine I'm using. Thanks again.