1#ifndef RAPIDXML_PRINT_HPP_INCLUDED
2#define RAPIDXML_PRINT_HPP_INCLUDED
13#ifndef RAPIDXML_NO_STREAMS
38 template <
class OutIt,
class Ch>
40 copy_chars(
const Ch* begin,
const Ch* end, OutIt out)
52 template <
class OutIt,
class Ch>
54 copy_and_expand_chars(
const Ch* begin,
const Ch* end, Ch noexpand, OutIt out)
58 if (*begin == noexpand)
118 template <
class OutIt,
class Ch>
120 fill_chars(OutIt out,
int n, Ch ch)
122 for (
int i = 0; i < n; ++i)
131 template <
class Ch, Ch ch>
133 find_char(
const Ch* begin,
const Ch* end)
149 template <
class OutIt,
class Ch>
150 OutIt print_children(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
152 template <
class OutIt,
class Ch>
153 inline OutIt print_element_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
155 template <
class OutIt,
class Ch>
156 inline OutIt print_attributes(OutIt out,
const xml_node<Ch>* node,
int flags);
158 template <
class OutIt,
class Ch>
159 inline OutIt print_data_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
161 template <
class OutIt,
class Ch>
162 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
164 template <
class OutIt,
class Ch>
166 print_declaration_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
168 template <
class OutIt,
class Ch>
169 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
171 template <
class OutIt,
class Ch>
172 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
174 template <
class OutIt,
class Ch>
175 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
178 template <
class OutIt,
class Ch>
180 print_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
183 switch (node->
type())
188 out = print_children(out, node, flags, indent);
193 out = print_element_node(out, node, flags, indent);
198 out = print_data_node(out, node, flags, indent);
203 out = print_cdata_node(out, node, flags, indent);
208 out = print_declaration_node(out, node, flags, indent);
213 out = print_comment_node(out, node, flags, indent);
218 out = print_doctype_node(out, node, flags, indent);
223 out = print_pi_node(out, node, flags, indent);
235 *out = Ch(
'\n'), ++out;
243 template <
class OutIt,
class Ch>
245 print_children(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
249 out = print_node(out, child, flags, indent);
256 template <
class OutIt,
class Ch>
258 print_attributes(OutIt out,
const xml_node<Ch>* node,
int flags)
263 if (attribute->name() && attribute->value())
266 *out = Ch(
' '), ++out;
268 attribute->name(), attribute->name() + attribute->name_size(), out);
269 *out = Ch(
'='), ++out;
272 if (find_char<Ch, Ch(
'"')>(attribute->value(),
273 attribute->value() + attribute->value_size()))
275 *out = Ch(
'\''), ++out;
276 out = copy_and_expand_chars(attribute->value(),
277 attribute->value() + attribute->value_size(),
280 *out = Ch(
'\''), ++out;
284 *out = Ch(
'"'), ++out;
285 out = copy_and_expand_chars(attribute->value(),
286 attribute->value() + attribute->value_size(),
289 *out = Ch(
'"'), ++out;
298 template <
class OutIt,
class Ch>
300 print_data_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
306 out = fill_chars(out, indent, Ch(
'\t'));
309 out = copy_and_expand_chars(
315 template <
class OutIt,
class Ch>
317 print_cdata_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
323 out = fill_chars(out, indent, Ch(
'\t'));
355 template <
class OutIt,
class Ch>
357 print_element_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
364 out = fill_chars(out, indent, Ch(
'\t'));
367 *out = Ch(
'<'), ++out;
369 out = print_attributes(out, node, flags);
375 *out = Ch(
'/'), ++out;
376 *out = Ch(
'>'), ++out;
381 *out = Ch(
'>'), ++out;
389 out = copy_and_expand_chars(
395 out = copy_and_expand_chars(
403 *out = Ch(
'\n'), ++out;
406 out = print_children(out, node, flags, indent + 1);
410 out = fill_chars(out, indent, Ch(
'\t'));
415 *out = Ch(
'<'), ++out;
416 *out = Ch(
'/'), ++out;
418 *out = Ch(
'>'), ++out;
425 template <
class OutIt,
class Ch>
427 print_declaration_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
432 out = fill_chars(out, indent, Ch(
'\t'));
435 *out = Ch(
'<'), ++out;
436 *out = Ch(
'?'), ++out;
437 *out = Ch(
'x'), ++out;
438 *out = Ch(
'm'), ++out;
439 *out = Ch(
'l'), ++out;
442 out = print_attributes(out, node, flags);
445 *out = Ch(
'?'), ++out;
446 *out = Ch(
'>'), ++out;
452 template <
class OutIt,
class Ch>
454 print_comment_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
460 out = fill_chars(out, indent, Ch(
'\t'));
463 *out = Ch(
'<'), ++out;
464 *out = Ch(
'!'), ++out;
465 *out = Ch(
'-'), ++out;
466 *out = Ch(
'-'), ++out;
468 *out = Ch(
'-'), ++out;
469 *out = Ch(
'-'), ++out;
470 *out = Ch(
'>'), ++out;
475 template <
class OutIt,
class Ch>
477 print_doctype_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
483 out = fill_chars(out, indent, Ch(
'\t'));
486 *out = Ch(
'<'), ++out;
487 *out = Ch(
'!'), ++out;
488 *out = Ch(
'D'), ++out;
489 *out = Ch(
'O'), ++out;
490 *out = Ch(
'C'), ++out;
491 *out = Ch(
'T'), ++out;
492 *out = Ch(
'Y'), ++out;
493 *out = Ch(
'P'), ++out;
494 *out = Ch(
'E'), ++out;
495 *out = Ch(
' '), ++out;
497 *out = Ch(
'>'), ++out;
502 template <
class OutIt,
class Ch>
504 print_pi_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
510 out = fill_chars(out, indent, Ch(
'\t'));
513 *out = Ch(
'<'), ++out;
514 *out = Ch(
'?'), ++out;
516 *out = Ch(
' '), ++out;
518 *out = Ch(
'?'), ++out;
519 *out = Ch(
'>'), ++out;
535 template <
class OutIt,
class Ch>
539 return internal::print_node(out, &node, flags, 0);
542#ifndef RAPIDXML_NO_STREAMS
550 inline std::basic_ostream<Ch>&
553 print(std::ostream_iterator<Ch>(out), node, flags);
562 inline std::basic_ostream<Ch>&
563 operator<<(std::basic_ostream<Ch>& out,
const xml_node<Ch>& node)
565 return print(out, node);
Class representing attribute node of XML document.
xml_attribute< Ch > * next_attribute(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets next attribute, optionally matching attribute name.
Ch * value() const
Gets value of node.
std::size_t value_size() const
Gets size of node value, not including terminator character.
std::size_t name_size() const
Gets size of node name, not including terminator character.
Ch * name() const
Gets name of the node.
Class representing a node of XML document.
node_type type() const
Gets type of node.
xml_node< Ch > * next_sibling(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets next sibling node, optionally matching node name.
xml_node< Ch > * first_node(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets first child node, optionally matching node name.
xml_attribute< Ch > * first_attribute(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets first attribute of node, optionally matching attribute name.
std::basic_ostream< Ch > & operator<<(std::basic_ostream< Ch > &out, const xml_node< Ch > &node)
Prints formatted XML to given output stream.
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Prints XML to given output iterator.
@ node_document
A document node. Name and value are empty.
@ node_pi
A PI node. Name contains target. Value contains instructions.
@ node_cdata
A CDATA node. Name is empty. Value contains data text.
@ node_data
A data node. Name is empty. Value contains data text.
@ node_doctype
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
@ node_element
An element node. Name contains element name. Value contains text of first data node.
@ node_comment
A comment node. Name is empty. Value contains comment text.
@ node_declaration
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
const int print_no_indenting
Printer flag instructing the printer to suppress indenting of XML. See print() function.
This file contains rapidxml parser and DOM implementation.