1 #ifndef RAPIDXML_PRINT_HPP_INCLUDED 2 #define RAPIDXML_PRINT_HPP_INCLUDED 12 #ifndef RAPIDXML_NO_STREAMS 36 template<
class OutIt,
class Ch>
37 inline OutIt copy_chars(
const Ch *begin,
const Ch *end, OutIt out)
46 template<
class OutIt,
class Ch>
47 inline OutIt copy_and_expand_chars(
const Ch *begin,
const Ch *end, Ch noexpand, OutIt out)
51 if (*begin == noexpand)
60 *out++ = Ch(
'&'); *out++ = Ch(
'l'); *out++ = Ch(
't'); *out++ = Ch(
';');
63 *out++ = Ch(
'&'); *out++ = Ch(
'g'); *out++ = Ch(
't'); *out++ = Ch(
';');
66 *out++ = Ch(
'&'); *out++ = Ch(
'a'); *out++ = Ch(
'p'); *out++ = Ch(
'o'); *out++ = Ch(
's'); *out++ = Ch(
';');
69 *out++ = Ch(
'&'); *out++ = Ch(
'q'); *out++ = Ch(
'u'); *out++ = Ch(
'o'); *out++ = Ch(
't'); *out++ = Ch(
';');
72 *out++ = Ch(
'&'); *out++ = Ch(
'a'); *out++ = Ch(
'm'); *out++ = Ch(
'p'); *out++ = Ch(
';');
84 template<
class OutIt,
class Ch>
85 inline OutIt fill_chars(OutIt out,
int n, Ch ch)
87 for (
int i = 0; i < n; ++i)
93 template<
class Ch, Ch ch>
94 inline bool find_char(
const Ch *begin,
const Ch *end)
105 template<
class OutIt,
class Ch>
106 inline OutIt print_node(OutIt,
const xml_node<Ch>*,
int,
int);
109 template<
class OutIt,
class Ch>
110 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
113 out = print_node(out, child, flags, indent);
118 template<
class OutIt,
class Ch>
119 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags)
123 if (attribute->name() && attribute->value())
126 *out = Ch(
' '), ++out;
127 out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
128 *out = Ch(
'='), ++out;
130 if (find_char<Ch, Ch(
'"')>(attribute->value(), attribute->value() + attribute->value_size()))
132 *out = Ch(
'\''), ++out;
133 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'"'), out);
134 *out = Ch(
'\''), ++out;
138 *out = Ch(
'"'), ++out;
139 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'\''), out);
140 *out = Ch(
'"'), ++out;
148 template<
class OutIt,
class Ch>
149 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
152 if (!(flags & print_no_indenting))
153 out = fill_chars(out, indent, Ch(
'\t'));
159 template<
class OutIt,
class Ch>
160 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
163 if (!(flags & print_no_indenting))
164 out = fill_chars(out, indent, Ch(
'\t'));
165 *out = Ch(
'<'); ++out;
166 *out = Ch(
'!'); ++out;
167 *out = Ch(
'['); ++out;
168 *out = Ch(
'C'); ++out;
169 *out = Ch(
'D'); ++out;
170 *out = Ch(
'A'); ++out;
171 *out = Ch(
'T'); ++out;
172 *out = Ch(
'A'); ++out;
173 *out = Ch(
'['); ++out;
175 *out = Ch(
']'); ++out;
176 *out = Ch(
']'); ++out;
177 *out = Ch(
'>'); ++out;
182 template<
class OutIt,
class Ch>
183 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
188 if (!(flags & print_no_indenting))
189 out = fill_chars(out, indent, Ch(
'\t'));
190 *out = Ch(
'<'), ++out;
192 out = print_attributes(out, node, flags);
198 *out = Ch(
'/'), ++out;
199 *out = Ch(
'>'), ++out;
204 *out = Ch(
'>'), ++out;
221 if (!(flags & print_no_indenting))
222 *out = Ch(
'\n'), ++out;
223 out = print_children(out, node, flags, indent + 1);
224 if (!(flags & print_no_indenting))
225 out = fill_chars(out, indent, Ch(
'\t'));
229 *out = Ch(
'<'), ++out;
230 *out = Ch(
'/'), ++out;
232 *out = Ch(
'>'), ++out;
238 template<
class OutIt,
class Ch>
239 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
242 if (!(flags & print_no_indenting))
243 out = fill_chars(out, indent, Ch(
'\t'));
244 *out = Ch(
'<'), ++out;
245 *out = Ch(
'?'), ++out;
246 *out = Ch(
'x'), ++out;
247 *out = Ch(
'm'), ++out;
248 *out = Ch(
'l'), ++out;
251 out = print_attributes(out, node, flags);
254 *out = Ch(
'?'), ++out;
255 *out = Ch(
'>'), ++out;
261 template<
class OutIt,
class Ch>
262 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
265 if (!(flags & print_no_indenting))
266 out = fill_chars(out, indent, Ch(
'\t'));
267 *out = Ch(
'<'), ++out;
268 *out = Ch(
'!'), ++out;
269 *out = Ch(
'-'), ++out;
270 *out = Ch(
'-'), ++out;
272 *out = Ch(
'-'), ++out;
273 *out = Ch(
'-'), ++out;
274 *out = Ch(
'>'), ++out;
279 template<
class OutIt,
class Ch>
280 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
283 if (!(flags & print_no_indenting))
284 out = fill_chars(out, indent, Ch(
'\t'));
285 *out = Ch(
'<'), ++out;
286 *out = Ch(
'!'), ++out;
287 *out = Ch(
'D'), ++out;
288 *out = Ch(
'O'), ++out;
289 *out = Ch(
'C'), ++out;
290 *out = Ch(
'T'), ++out;
291 *out = Ch(
'Y'), ++out;
292 *out = Ch(
'P'), ++out;
293 *out = Ch(
'E'), ++out;
294 *out = Ch(
' '), ++out;
296 *out = Ch(
'>'), ++out;
301 template<
class OutIt,
class Ch>
302 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
305 if (!(flags & print_no_indenting))
306 out = fill_chars(out, indent, Ch(
'\t'));
307 *out = Ch(
'<'), ++out;
308 *out = Ch(
'?'), ++out;
310 *out = Ch(
' '), ++out;
312 *out = Ch(
'?'), ++out;
313 *out = Ch(
'>'), ++out;
318 template<
class OutIt,
class Ch>
319 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
322 switch (node->
type())
327 out = print_children(out, node, flags, indent);
332 out = print_element_node(out, node, flags, indent);
337 out = print_data_node(out, node, flags, indent);
342 out = print_cdata_node(out, node, flags, indent);
347 out = print_declaration_node(out, node, flags, indent);
352 out = print_comment_node(out, node, flags, indent);
357 out = print_doctype_node(out, node, flags, indent);
362 out = print_pi_node(out, node, flags, indent);
372 if (!(flags & print_no_indenting))
373 *out = Ch(
'\n'), ++out;
391 template<
class OutIt,
class Ch>
394 return internal::print_node(out, &node, flags, 0);
397 #ifndef RAPIDXML_NO_STREAMS 405 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node,
int flags = 0)
407 print(std::ostream_iterator<Ch>(out), node, flags);
416 inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node)
418 return print(out, node);
This file contains rapidxml parser and DOM implementation.
A PI node. Name contains target. Value contains instructions.
Definition: rapidxml.hpp:152
A CDATA node. Name is empty. Value contains data text.
Definition: rapidxml.hpp:148
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
Definition: rapidxml.hpp:151
Ch * value() const
Definition: rapidxml.hpp:692
std::size_t name_size() const
Definition: rapidxml.hpp:681
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:936
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Definition: rapidxml_print.hpp:392
A document node. Name and value are empty.
Definition: rapidxml.hpp:145
node_type type() const
Definition: rapidxml.hpp:913
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
Definition: rapidxml.hpp:150
Ch * name() const
Definition: rapidxml.hpp:673
const int print_no_indenting
Printer flag instructing the printer to suppress indenting of XML. See print() function.
Definition: rapidxml_print.hpp:23
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
Definition: rapidxml.hpp:138
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1004
An element node. Name contains element name. Value contains text of first data node.
Definition: rapidxml.hpp:146
Definition: rapidxml.hpp:137
Definition: rapidxml.hpp:57
A comment node. Name is empty. Value contains comment text.
Definition: rapidxml.hpp:149
A data node. Name is empty. Value contains data text.
Definition: rapidxml.hpp:147
std::size_t value_size() const
Definition: rapidxml.hpp:700