1 #include <sngxml/xml/XmlParserInterface.hpp>
2 #include <soulng/util/InitDone.hpp>
3 #include <soulng/util/Path.hpp>
4 #include <iostream>
5 #include <stdexcept>
6 #include <stdlib.h>
7
8 using namespace soulng::util;
9
10
11
12
13
14
15
16
17 struct MyContentHandler : public sngxml::xml::XmlContentHandler
18 {
19 void StartElement(const std::u32string& namespaceUri, const std::u32string& localName, const std::u32string& qualifiedName, const sngxml::xml::Attributes& attributes) override
20 {
21 if (localName == U"foo")
22 {
23 std::cout << "foo found" << std::endl;
24 }
25 }
26 };
27
28 std::string GetSoulNGRootDir()
29 {
30 const char* soulngRootEnv = getenv("SOULNG_ROOT");
31 std::string soulngRootDir;
32 if (soulngRootEnv)
33 {
34 soulngRootDir = soulngRootEnv;
35 }
36 if (soulngRootDir.empty())
37 {
38 throw std::runtime_error("please set SOULNG_ROOT environment variable to point to /path/to/soulng directory");
39 }
40 return soulngRootDir;
41 }
42
43 struct Initializer
44 {
45 Initializer()
46 {
47 soulng::util::Init();
48 }
49 ~Initializer()
50 {
51 soulng::util::Done();
52 }
53 };
54
55 int main()
56 {
57 Initializer initializer;
58 try
59 {
60 MyContentHandler contentHandler;
61 sngxml::xml::ParseXmlFile(Path::Combine(GetSoulNGRootDir(), "examples/sngxml/foo.xml"), &contentHandler);
62 }
63 catch (const std::exception& ex;)
64 {
65 std::cerr << ex.what() << std::endl;
66 return 1;
67 }
68 return 0;
69 }