summaryrefslogtreecommitdiffstats
path: root/examples/xml/tagreader-with-features/structureparser.cpp
blob: 5d9559efcc2111487c8f5401412251f043cb5d2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
*/

#include "structureparser.h"

#include <tqstring.h>
#include <tqlistview.h>

StructureParser::StructureParser( TQListView * t )
                : TQXmlDefaultHandler()
{
    setListView( t );
}

void StructureParser::setListView( TQListView * t )
{
    table = t;
    table->setSorting( -1 );
    table->addColumn( "Qualified name" );
    table->addColumn( "Namespace" );
}

bool StructureParser::startElement( const TQString& namespaceURI,
                                    const TQString& ,
                                    const TQString& qName,
                                    const TQXmlAttributes& attributes)
{
    TQListViewItem * element;

    if ( ! stack.isEmpty() ){
	TQListViewItem *lastChild = stack.top()->firstChild();
	if ( lastChild ) {
	    while ( lastChild->nextSibling() )
		lastChild = lastChild->nextSibling();
	}
	element = new TQListViewItem( stack.top(), lastChild, qName, namespaceURI );
    } else {
	element = new TQListViewItem( table, qName, namespaceURI );
    }
    stack.push( element );
    element->setOpen( true );

    if ( attributes.length() > 0 ) {
	for ( int i = 0 ; i < attributes.length(); i++ ) {
	    new TQListViewItem( element, attributes.qName(i), attributes.uri(i) );
	}
    }
    return true;
}

bool StructureParser::endElement( const TQString&, const TQString&,
                                  const TQString& )
{
    stack.pop();
    return true;
}