author | František Kučera <franta-hg@frantovo.cz> |
Wed, 24 Jul 2019 12:15:10 +0200 | |
branch | v_0 |
changeset 0 | a37196931f63 |
child 2 | 0d3eb5129582 |
permissions | -rw-r--r-- |
0
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* (at your option) any later version. |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
*/ |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#pragma once |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <cstdlib> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <iostream> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <string> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <sstream> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <vector> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include <algorithm> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
#include <libxml++-2.6/libxml++/libxml++.h> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
#include <relpipe/writer/typedefs.h> |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
namespace relpipe { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
namespace in { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
namespace xmltable { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
using namespace relpipe::writer; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
class XMLCommand { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
private: |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
public: |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
void process(std::istream& input, std::ostream& output) { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
xmlpp::DomParser parser; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
parser.parse_stream(input); |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
xmlpp::Document* d = parser.get_document(); |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
xmlpp::Element* r = d->get_root_node(); |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
xmlpp::Node::PrefixNsMap m; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
m["rp"] = "tag:globalcode.info,2018:relpipe"; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
output << "root: " << r->get_name() << std::endl; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
for (xmlpp::Node* n : r->find("//rp:attribute", m)) { |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
output << "node:" << n->get_name() << std::endl; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
} |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
} |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
}; |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
|
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
} |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
} |
a37196931f63
project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
} |