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) {
38 while (begin != end) *out++ = *begin++;
44 template <
class OutIt,
class Ch>
45 inline OutIt copy_and_expand_chars(
const Ch *begin,
const Ch *end, Ch noexpand,
47 while (begin != end) {
48 if (*begin == noexpand) {
97 template <
class OutIt,
class Ch>
98 inline OutIt fill_chars(OutIt out,
int n, Ch ch) {
99 for (
int i = 0; i < n; ++i) *out++ = ch;
104 template <
class Ch, Ch ch>
105 inline bool find_char(
const Ch *begin,
const Ch *end) {
107 if (*begin++ == ch)
return true;
115 template <
class OutIt,
class Ch>
116 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
119 switch (node->
type()) {
122 out = print_children(out, node, flags, indent);
127 out = print_element_node(out, node, flags, indent);
132 out = print_data_node(out, node, flags, indent);
137 out = print_cdata_node(out, node, flags, indent);
142 out = print_declaration_node(out, node, flags, indent);
147 out = print_comment_node(out, node, flags, indent);
152 out = print_doctype_node(out, node, flags, indent);
157 out = print_pi_node(out, node, flags, indent);
167 if (!(flags & print_no_indenting)) *out = Ch(
'\n'), ++out;
174 template <
class OutIt,
class Ch>
175 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
178 child = child->next_sibling())
179 out = print_node(out, child, flags, indent);
184 template <
class OutIt,
class Ch>
185 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags) {
187 attribute = attribute->next_attribute()) {
188 if (attribute->name() && attribute->value()) {
190 *out = Ch(
' '), ++out;
191 out = copy_chars(attribute->name(),
192 attribute->name() + attribute->name_size(), out);
193 *out = Ch(
'='), ++out;
195 if (find_char<Ch, Ch(
'"')>(
197 attribute->value() + attribute->value_size())) {
198 *out = Ch(
'\''), ++out;
199 out = copy_and_expand_chars(
200 attribute->value(), attribute->value() + attribute->value_size(),
202 *out = Ch(
'\''), ++out;
204 *out = Ch(
'"'), ++out;
205 out = copy_and_expand_chars(
206 attribute->value(), attribute->value() + attribute->value_size(),
208 *out = Ch(
'"'), ++out;
216 template <
class OutIt,
class Ch>
217 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
220 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
227 template <
class OutIt,
class Ch>
228 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
231 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
261 template <
class OutIt,
class Ch>
262 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
267 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
268 *out = Ch(
'<'), ++out;
270 out = print_attributes(out, node, flags);
275 *out = Ch(
'/'), ++out;
276 *out = Ch(
'>'), ++out;
279 *out = Ch(
'>'), ++out;
285 out = copy_and_expand_chars(
289 out = copy_and_expand_chars(
293 if (!(flags & print_no_indenting)) *out = Ch(
'\n'), ++out;
294 out = print_children(out, node, flags, indent + 1);
295 if (!(flags & print_no_indenting))
296 out = fill_chars(out, indent, Ch(
'\t'));
300 *out = Ch(
'<'), ++out;
301 *out = Ch(
'/'), ++out;
303 *out = Ch(
'>'), ++out;
309 template <
class OutIt,
class Ch>
310 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
311 int flags,
int indent) {
313 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
314 *out = Ch(
'<'), ++out;
315 *out = Ch(
'?'), ++out;
316 *out = Ch(
'x'), ++out;
317 *out = Ch(
'm'), ++out;
318 *out = Ch(
'l'), ++out;
321 out = print_attributes(out, node, flags);
324 *out = Ch(
'?'), ++out;
325 *out = Ch(
'>'), ++out;
331 template <
class OutIt,
class Ch>
332 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
335 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
336 *out = Ch(
'<'), ++out;
337 *out = Ch(
'!'), ++out;
338 *out = Ch(
'-'), ++out;
339 *out = Ch(
'-'), ++out;
341 *out = Ch(
'-'), ++out;
342 *out = Ch(
'-'), ++out;
343 *out = Ch(
'>'), ++out;
348 template <
class OutIt,
class Ch>
349 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
352 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
353 *out = Ch(
'<'), ++out;
354 *out = Ch(
'!'), ++out;
355 *out = Ch(
'D'), ++out;
356 *out = Ch(
'O'), ++out;
357 *out = Ch(
'C'), ++out;
358 *out = Ch(
'T'), ++out;
359 *out = Ch(
'Y'), ++out;
360 *out = Ch(
'P'), ++out;
361 *out = Ch(
'E'), ++out;
362 *out = Ch(
' '), ++out;
364 *out = Ch(
'>'), ++out;
369 template <
class OutIt,
class Ch>
370 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
373 if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch(
'\t'));
374 *out = Ch(
'<'), ++out;
375 *out = Ch(
'?'), ++out;
377 *out = Ch(
' '), ++out;
379 *out = Ch(
'?'), ++out;
380 *out = Ch(
'>'), ++out;
396 template <
class OutIt,
class Ch>
398 return internal::print_node(out, &node, flags, 0);
401 #ifndef RAPIDXML_NO_STREAMS 409 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
411 print(std::ostream_iterator<Ch>(out), node, flags);
419 inline std::basic_ostream<Ch> &operator<<(std::basic_ostream<Ch> &out,
421 return print(out, node);
This file contains rapidxml parser and DOM implementation.
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
std::size_t name_size() const
A CDATA node. Name is empty. Value contains data text.
A document node. Name and value are empty.
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
const int print_no_indenting
A data node. Name is empty. Value contains data text.
A PI node. Name contains target. Value contains instructions.
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
std::size_t value_size() const