summaryrefslogtreecommitdiff
path: root/tests/textwolf/test2.cpp
blob: 849a485e5f35064e938a38cf7a8f5ebc3aeb53a8 (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
#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: test2 <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 enum {
		SITEMAP_LOC = 1
	} XmlNodes;
	typedef XMLPathSelectAutomaton<charset::UTF8> Automaton;
	Automaton atm;
	// //sitemap/loc content
	(*atm)--["sitemap"]["loc"]( ) = SITEMAP_LOC;
	
	typedef XMLPathSelect<charset::UTF8> PathSelect;
	typedef XMLScanner<IStreamIterator, charset::UTF8, charset::UTF8, std::string> Scanner;
	Scanner xsc( isitr );
	PathSelect xsel( &atm );
	
	Scanner::iterator ci, ce;
	for( ci = xsc.begin( ), ce = xsc.end( ); ci != ce; ci++ ) {
		if( ci->type( ) == Scanner::ErrorOccurred ) {
			throw std::runtime_error( ci->content( ) );
		}
		
		PathSelect::iterator itr = xsel.push( ci->type( ), ci->content( ), ci->size( ) );
		PathSelect::iterator end = xsel.end( );
		for( ; itr != end; itr++ ) {
			if( *itr == SITEMAP_LOC ) {
				cout << ci->content( ) << endl;
			}
		}
	}
}