1 #include <sngxml/dom/Parser.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 std::string GetSoulNGRootDir()
11 {
12 const char* soulngRootEnv = getenv("SOULNG_ROOT");
13 std::string soulngRootDir;
14 if (soulngRootEnv)
15 {
16 soulngRootDir = soulngRootEnv;
17 }
18 if (soulngRootDir.empty())
19 {
20 throw std::runtime_error("please set SOULNG_ROOT environment variable to point to /path/to/soulng directory");
21 }
22 return soulngRootDir;
23 }
24
25 struct Initializer
26 {
27 Initializer()
28 {
29 soulng::util::Init();
30 }
31 ~Initializer()
32 {
33 soulng::util::Done();
34 }
35 };
36
37
38
39
40
41
42
43
44 int main()
45 {
46 Initializer initializer;
47 try
48 {
49 std::unique_ptr<sngxml::dom::Document> xmlDoc = sngxml::dom::ReadDocument(GetFullPath(Path::Combine(GetSoulNGRootDir(), "examples/sngxml/foo.xml")));
50 CodeFormatter formatter(std::cout);
51 xmlDoc->Write(formatter);
52 }
53 catch (const std::exception& ex;)
54 {
55 std::cerr << ex.what() << std::endl;
56 return 1;
57 }
58 return 0;
59 }