sax parsing & hierarchical relationships

smapdi636

New Member
I'm banging my head against the wall a bit with regards to the sax parser & hierarchical relationships.

Suppose I have some xml representing a hierarchical relationship that I wanted to store inside a table ... something like:

Code:
<category id="0">
  <category id="1">
    <category id="2" />
  </category>
  <category id="3" />
</category>
I'd generally store this inside a table with a id and parent_id fields like:

Code:
category
---------
id
parent_id
If parent_id = ? I'd know the record was root-level, otherwise it'd be a child of its parent_id. I'd maybe add a sequence field if I needed to keep track of exact order of elements...

So conceptualizing parsing the above XML with the sax parser, I'm having a hard time understanding how to know when a category element is a child (and if so, of what parent).

Code:
procedure StartElement:
  def input param ip_namespace_uri as char no-undo.
  def input param ip_localname as char no-undo.
  def input param ip_qname as char no-undo.
  def input param iph_attributes as handle.

  case ip_qname:
  
    when "category" then do:

      /* how do I know who my parent is? */    
    
    end.
  
  end case.
  
end.
I mean I probably could mechanically kludge something out using temp-tables to keep track but I'm thinking that I'm either missing something very simple or that there must be a more graceful way than temp-tables (recursion or something). Any ideas?
 
Top