home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / xml / tagreader-with-features / structureparser.cpp < prev    next >
C/C++ Source or Header  |  2001-10-11  |  1KB  |  53 lines

  1. /*
  2. $Id$
  3. */
  4.  
  5. #include "structureparser.h"
  6.  
  7. #include <qstring.h>
  8. #include <qlistview.h>
  9.  
  10. StructureParser::StructureParser( QListView * t )
  11.                 : QXmlDefaultHandler() 
  12. {
  13.     setListView( t );
  14. }
  15.  
  16. void StructureParser::setListView( QListView * t )
  17. {
  18.     table = t;
  19.     table->setSorting( -1 );
  20.     table->addColumn( "Qualified name" );
  21.     table->addColumn( "Namespace" );
  22. }
  23.  
  24. bool StructureParser::startElement( const QString& namespaceURI, 
  25.                                     const QString& , 
  26.                                     const QString& qName, 
  27.                                     const QXmlAttributes& attributes)
  28. {
  29.     QListViewItem * element;
  30.  
  31.     if ( ! stack.isEmpty() ){
  32.     element = new QListViewItem( stack.top(), qName, namespaceURI );
  33.     } else {
  34.     element = new QListViewItem( table, qName, namespaceURI );
  35.     }
  36.     stack.push( element );
  37.     element->setOpen( TRUE );
  38.  
  39.     if ( attributes.length() > 0 ) {
  40.     for ( int i = 0 ; i < attributes.length(); i++ ) {
  41.         new QListViewItem( element, attributes.qName(i), attributes.uri(i) );
  42.     }
  43.     }
  44.     return TRUE;
  45. }
  46.  
  47. bool StructureParser::endElement( const QString&, const QString&, 
  48.                                   const QString& )
  49. {
  50.     stack.pop();
  51.     return TRUE;
  52. }
  53.