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
66
67
68
|
#include "pugixml.hpp"
#include <fstream>
#include <iomanip>
#include <iostream>
void print_doc(const char* message, const pugi::xml_document& doc, const pugi::xml_parse_result& result)
{
std::cout
<< message
<< "\t: load result '" << result.description() << "'"
<< ", first character of root name: U+" << std::hex << std::uppercase << std::setw(4) << std::setfill('0') << pugi::as_wide(doc.first_child().name())[0]
<< ", year: " << doc.first_child().first_child().first_child().child_value()
<< std::endl;
}
int main()
{
pugi::xml_document doc;
{
std::ifstream stream("weekly-utf-8.xml");
pugi::xml_parse_result result = doc.load(stream);
print_doc("UTF8 file from narrow stream", doc, result);
}
{
std::ifstream stream("weekly-utf-16.xml");
pugi::xml_parse_result result = doc.load(stream);
print_doc("UTF16 file from narrow stream", doc, result);
}
{
std::wifstream stream("weekly-utf-8.xml");
pugi::xml_parse_result result = doc.load(stream);
print_doc("UTF8 file from wide stream", doc, result);
}
{
std::wifstream stream("weekly-utf-16.xml");
pugi::xml_parse_result result = doc.load(stream);
print_doc("UTF16 file from wide stream", doc, result);
}
{
std::wifstream stream("weekly-shift_jis.xml");
stream.imbue(std::locale(".932"));
pugi::xml_parse_result result = doc.load(stream);
print_doc("Shift-JIS file from wide stream", doc, result);
}
}
|