in reply to Nesting below emptiness and/or inverting a hash.

Excuse me while I completely ignoring your interesting question about hash inversions. But, have you tried XML::Twig, it is usually a good choice for dealing with large XML trees.

Returning to your question... usually you need a push down stack to handle recursive parsing like you are describing. When you see an opening tag, push it. When you see a closing tag pop it. In between walk up or down the stack's array to see where you are at present.

Phil

  • Comment on Re: Nesting below emptiness and/or inverting a hash.

Replies are listed 'Best First'.
Re^2: Nesting below emptiness and/or inverting a hash.
by Moron (Curate) on Jan 22, 2007 at 16:35 UTC
    A stack may help to invert and reconstruct the hash from recursive context - I will certainly see what I can do with that suggestion, thanks!

    (Update: but I will want to avoid any walking around the stack - "where I am" is easy in the particular case because I have an instance variable for it. As a rule it is best to stick to pushing and popping.)

    re XML::Twig, there were other requirments that needed to be met by various projects for my client, not just the size of the XML files and these were not met by XML::Parser or Expat. It was obvious fairly early on that I needed to be able to code features into the main part of the parser so I had to have control over it and new requirments since then have also deviated from what is currently availabkle in the XML namespace, such as tolerating extra characters between tags that do not conform to "standard" XML whatever that might be.

    XML::Twig suffers from my point of view in that respect from being built on XML::Parser.

    At some point I will have to make a list of the special features and think up a new name for the module. XML::Deviant perhaps ;)

    -M

    Free your mind