=begin
/*
$Id: qt/examples/xml/tagreader-with-features/structureparser.cpp   2.2.4   edited 2001-01-22 $
*/
=end

require "qt2"
include Qt2

require "qt2xml"
include Qt2xml

class StructureParser < QXmlRubyHandler
def initialize ()
  @stack = Array.new
  #call setListVie(t)
end

def setListView(t)
    @table = t
    @table.setSorting( -1 ) # no sorting
    @table.addColumn( "Qualified name" )
    @table.addColumn( "Namespace" )
end

def startDocument()

    return true
end

def startElement( namespaceURI, qstr1 , qName, attributes)

   element = nil

    if ( ! @stack.empty? )
	element = QListViewItem.new( @stack.last, qName, namespaceURI )
    else
	element = QListViewItem.new( @table, qName, namespaceURI )
    end
    @stack.push( element )
    element.setOpen( true )

    if ( attributes.length() > 0 )
        attribute = nil
	for i in 0..(attributes.length() - 1) #( int i = 0  i < attributes.length() i++ )
 	    attribute = QListViewItem.new( element, attributes.qName(i), attributes.uri(i) )
	end      
    end 
    return true
end

def endElement( qstr1, qstr2, qstr3 )

    @stack.pop()
    return true
end
end


