summaryrefslogtreecommitdiff
path: root/tests/textwolf/test1.cpp
blob: 426f931c61853fad04d525d3fab615f2fd8215af (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
57
58
59
60
61
62
63
64
65
#include "textwolf.hpp"
#include "textwolf/istreamiterator.hpp"

#include <iostream>
#include <fstream>

using namespace std;
using namespace textwolf;

int main( int argc, char *argv[] )
{
	if( argc != 2 ) {
		cerr << "Usage: test1 <XML file>\n" << endl;
		return 1;
	}
	
	char *xmlFileName = argv[1];
		
	ifstream xmlFile( xmlFileName );
	if( !xmlFile.good( ) ) {
		cerr << "ERROR: Can't open file '" << xmlFileName << "'" << endl;
		return 1;
	}

	IStreamIterator isitr( xmlFile );
	
	typedef XMLScanner<IStreamIterator, charset::UTF8, charset::UTF8, std::string> Scanner;
	Scanner xs( isitr );
	std::string currentTag;
	for( Scanner::iterator itr = xs.begin( ); itr != xs.end( ); itr++ ) {
		switch( itr->type( ) ) {
			case Scanner::OpenTag:
				currentTag = itr->content( );
				break;

			case Scanner::Content:
				if( currentTag == "loc" ) {
					cout << itr->content( ) << endl;
				}
				break;

			case Scanner::CloseTag:
				currentTag.clear( );
				break;

			case Scanner::ErrorOccurred:
				throw runtime_error( itr->content( ) );
				
			case Scanner::None:
			case Scanner::HeaderStart:
			case Scanner::HeaderAttribName:
			case Scanner::HeaderAttribValue:
			case Scanner::HeaderEnd:
			case Scanner::DocAttribValue:
			case Scanner::DocAttribEnd:
			case Scanner::TagAttribName:
			case Scanner::TagAttribValue:
			case Scanner::CloseTagIm:
			case Scanner::Exit:

			default:
				break;
		}
	}
}