summaryrefslogtreecommitdiffstats
path: root/test/src/test-arabica-parsing.cpp
blob: 24275fc68ae26bd8fe0a11c92c2d80bc220e6a2f (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
#include <iostream>

#include "uscxml/config.h"
#include "uscxml/Common.h"
#include <DOM/Document.hpp>
#include <XPath/XPath.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <DOM/io/Stream.hpp>
#include <SAX/helpers/CatchErrorHandler.hpp>
#include <DOM/Events/EventTarget.hpp>
#include <DOM/Events/EventListener.hpp>

using namespace Arabica::DOM;

int main(int argc, char** argv) {

	{
		std::stringstream* ss = new std::stringstream();
		(*ss) << "<root>\n<![CDATA[\n< \" ' < > &\n]]>\n</root>";
		// we need an auto_ptr for arabica to assume ownership
		std::auto_ptr<std::istream> ssPtr(ss);
		Arabica::SAX::InputSource<std::string> inputSource(ssPtr);

		Arabica::SAX2DOM::Parser<std::string> domParser;
		Arabica::SAX::CatchErrorHandler<std::string> errorHandler;
		domParser.setErrorHandler(errorHandler);

		if(!domParser.parse(inputSource)) {
			std::cout << errorHandler.errors();
			return -1;
		}
		std::cout << domParser.getDocument().getDocumentElement().getFirstChild().getNodeValue() << std::endl;
		std::cout << domParser.getDocument() << std::endl;
	}
	{
		Arabica::SAX::InputSource<std::string> inputSource;
		inputSource.setSystemId("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/arabica/test-arabica-parsing.xml");

		Arabica::SAX2DOM::Parser<std::string> domParser;
		Arabica::SAX::CatchErrorHandler<std::string> errorHandler;
		domParser.setErrorHandler(errorHandler);

		if(!domParser.parse(inputSource)) {
			std::cout << errorHandler.errors();
			return -1;
		}
		std::cout << domParser.getDocument() << std::endl;
	}

}