forked from cpp-netlib/cpp-netlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.cpp
More file actions
95 lines (79 loc) · 2.71 KB
/
Copy pathatom.cpp
File metadata and controls
95 lines (79 loc) · 2.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Glyn Matthews 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "atom.hpp"
#include "../rapidxml/rapidxml.hpp"
#include <stdexcept>
#include <cassert>
namespace boost {
namespace network {
namespace atom {
feed::feed(const http::client::response &response) {
std::string response_body = body(response);
rapidxml::xml_document<> doc;
doc.parse<0>(const_cast<char *>(response_body.c_str()));
rapidxml::xml_node<> *feed = doc.first_node("feed");
if (!feed) {
throw std::runtime_error("Invalid atom feed.");
}
rapidxml::xml_node<> *title = feed->first_node("title");
if (title) {
title_ = title->first_node()->value();
}
rapidxml::xml_node<> *subtitle = feed->first_node("subtitle");
if (subtitle) {
subtitle_ = subtitle->first_node()->value();
}
rapidxml::xml_node<> *id = feed->first_node("id");
if (id) {
id_ = id->first_node()->value();
}
rapidxml::xml_node<> *updated = feed->first_node("updated");
if (updated) {
updated_ = updated->first_node()->value();
}
rapidxml::xml_node<> *author = feed->first_node("author");
if (author) {
rapidxml::xml_node<> *name = author->first_node("name");
rapidxml::xml_node<> *email = author->first_node("email");
if (name && email) {
author_ = atom::author(name->first_node()->value(),
email->first_node()->value());
} else if (name) {
author_ = atom::author(name->first_node()->value());
}
}
rapidxml::xml_node<> *entry = feed->first_node("entry");
while (entry) {
entries_.push_back(atom::entry());
rapidxml::xml_node<> *title = entry->first_node("title");
if (title) {
entries_.back().set_title(title->first_node()->value());
}
rapidxml::xml_node<> *id = entry->first_node("id");
if (id) {
entries_.back().set_id(id->first_node()->value());
}
rapidxml::xml_node<> *published = entry->first_node("published");
if (published) {
entries_.back().set_published(published->first_node()->value());
}
rapidxml::xml_node<> *updated = entry->first_node("updated");
if (updated) {
entries_.back().set_updated(updated->first_node()->value());
}
rapidxml::xml_node<> *summary = entry->first_node("summary");
if (summary) {
entries_.back().set_summary(summary->first_node()->value());
}
rapidxml::xml_node<> *content = entry->first_node("content");
if (content) {
entries_.back().set_content(content->first_node()->value());
}
entry = entry->next_sibling();
}
}
} // namespace atom
} // namespace network
} // namespace boost