MLBookProc 1.1
 
Loading...
Searching...
No Matches
XMLParser.h
1/*
2 * Copyright (C) 2024-2025 Yury Bobylev <bobilev_yury@mail.ru>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, version 3.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#ifndef XMLPARSER_H
18#define XMLPARSER_H
19
20#include <AuxFunc.h>
21#include <MLException.h>
22#include <XMLTag.h>
23#include <memory>
24#include <string>
25#include <vector>
26
34{
35public:
40 XMLParser(const std::shared_ptr<AuxFunc> &af);
41
53 std::vector<XMLTag>
54 get_tag(const std::string &book, const std::string &tag_id);
55
68 std::string
69 get_book_encoding(const std::string &book);
70
78 std::string
79 get_element_attribute(const std::string &element,
80 const std::string &attr_name);
81
92 std::vector<XMLTag>
93 listAllTags(const std::string &book);
94
104 void
105 searchTag(const std::vector<XMLTag> &list, const std::string &tag_id,
106 std::vector<XMLTag> &result);
107
116 void
117 htmlSymbolsReplacement(std::string &book);
118
129 void
130 removeAllTags(std::string &book);
131
132private:
133 enum tag_type
134 {
135 single,
136 has_content,
137 end_tag,
138 spec_tag
139 };
140
141 std::string
142 tagElement(const std::string &book, const std::string::size_type &start,
143 std::string::size_type &end, tag_type &tg_type);
144
145 void
146 tagContent(const std::string &book, const std::string::size_type &start,
147 const std::string::size_type &book_end, XMLTag &tag,
148 std::string::size_type &tag_end);
149
150 void
151 tagId(XMLTag &tag);
152
153 std::shared_ptr<AuxFunc> af;
154};
155
156#endif // XMLPARSER_H
void searchTag(const std::vector< XMLTag > &list, const std::string &tag_id, std::vector< XMLTag > &result)
Searches tag in tag list.
void removeAllTags(std::string &book)
Removes all tag elements from XML document.
void htmlSymbolsReplacement(std::string &book)
Replaces symbols encoded by "&..." sequences.
std::vector< XMLTag > get_tag(const std::string &book, const std::string &tag_id)
Returns all tags with particular name.
std::vector< XMLTag > listAllTags(const std::string &book)
Parses XML document.
XMLParser(const std::shared_ptr< AuxFunc > &af)
XMLParser constructor.
std::string get_element_attribute(const std::string &element, const std::string &attr_name)
Returns XML tag attribute if it was found.
std::string get_book_encoding(const std::string &book)
Returns XML document encoding.
The XMLTag class.
Definition XMLTag.h:32