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)
104 template<
class OutIt,
class Ch>
105 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
107 template<
class OutIt,
class Ch>
108 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags);
110 template<
class OutIt,
class Ch>
111 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
113 template<
class OutIt,
class Ch>
114 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
116 template<
class OutIt,
class Ch>
117 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
119 template<
class OutIt,
class Ch>
120 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
122 template<
class OutIt,
class Ch>
123 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
125 template<
class OutIt,
class Ch>
126 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
128 template<
class OutIt,
class Ch>
129 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
131 template<
class OutIt,
class Ch>
132 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
135 switch (node->
type())
140 out = print_children(out, node, flags, indent);
145 out = print_element_node(out, node, flags, indent);
150 out = print_data_node(out, node, flags, indent);
155 out = print_cdata_node(out, node, flags, indent);
160 out = print_declaration_node(out, node, flags, indent);
165 out = print_comment_node(out, node, flags, indent);
170 out = print_doctype_node(out, node, flags, indent);
175 out = print_pi_node(out, node, flags, indent);
185 if (!(flags & print_no_indenting))
186 *out = Ch(
'\n'), ++out;
193 template<
class OutIt,
class Ch>
194 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
197 out = print_node(out, child, flags, indent);
202 template<
class OutIt,
class Ch>
203 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags)
207 if (attribute->name() && attribute->value())
210 *out = Ch(
' '), ++out;
211 out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
212 *out = Ch(
'='), ++out;
214 if (find_char<Ch, Ch(
'"')>(attribute->value(), attribute->value() + attribute->value_size()))
216 *out = Ch(
'\''), ++out;
217 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'"'), out);
218 *out = Ch(
'\''), ++out;
222 *out = Ch(
'"'), ++out;
223 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'\''), out);
224 *out = Ch(
'"'), ++out;
232 template<
class OutIt,
class Ch>
233 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
236 if (!(flags & print_no_indenting))
237 out = fill_chars(out, indent, Ch(
'\t'));
243 template<
class OutIt,
class Ch>
244 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
247 if (!(flags & print_no_indenting))
248 out = fill_chars(out, indent, Ch(
'\t'));
249 *out = Ch(
'<'); ++out;
250 *out = Ch(
'!'); ++out;
251 *out = Ch(
'['); ++out;
252 *out = Ch(
'C'); ++out;
253 *out = Ch(
'D'); ++out;
254 *out = Ch(
'A'); ++out;
255 *out = Ch(
'T'); ++out;
256 *out = Ch(
'A'); ++out;
257 *out = Ch(
'['); ++out;
259 *out = Ch(
']'); ++out;
260 *out = Ch(
']'); ++out;
261 *out = Ch(
'>'); ++out;
266 template<
class OutIt,
class Ch>
267 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
272 if (!(flags & print_no_indenting))
273 out = fill_chars(out, indent, Ch(
'\t'));
274 *out = Ch(
'<'), ++out;
276 out = print_attributes(out, node, flags);
282 *out = Ch(
'/'), ++out;
283 *out = Ch(
'>'), ++out;
288 *out = Ch(
'>'), ++out;
305 if (!(flags & print_no_indenting))
306 *out = Ch(
'\n'), ++out;
307 out = print_children(out, node, flags, indent + 1);
308 if (!(flags & print_no_indenting))
309 out = fill_chars(out, indent, Ch(
'\t'));
313 *out = Ch(
'<'), ++out;
314 *out = Ch(
'/'), ++out;
316 *out = Ch(
'>'), ++out;
322 template<
class OutIt,
class Ch>
323 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
326 if (!(flags & print_no_indenting))
327 out = fill_chars(out, indent, Ch(
'\t'));
328 *out = Ch(
'<'), ++out;
329 *out = Ch(
'?'), ++out;
330 *out = Ch(
'x'), ++out;
331 *out = Ch(
'm'), ++out;
332 *out = Ch(
'l'), ++out;
335 out = print_attributes(out, node, flags);
338 *out = Ch(
'?'), ++out;
339 *out = Ch(
'>'), ++out;
345 template<
class OutIt,
class Ch>
346 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
349 if (!(flags & print_no_indenting))
350 out = fill_chars(out, indent, Ch(
'\t'));
351 *out = Ch(
'<'), ++out;
352 *out = Ch(
'!'), ++out;
353 *out = Ch(
'-'), ++out;
354 *out = Ch(
'-'), ++out;
356 *out = Ch(
'-'), ++out;
357 *out = Ch(
'-'), ++out;
358 *out = Ch(
'>'), ++out;
363 template<
class OutIt,
class Ch>
364 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
367 if (!(flags & print_no_indenting))
368 out = fill_chars(out, indent, Ch(
'\t'));
369 *out = Ch(
'<'), ++out;
370 *out = Ch(
'!'), ++out;
371 *out = Ch(
'D'), ++out;
372 *out = Ch(
'O'), ++out;
373 *out = Ch(
'C'), ++out;
374 *out = Ch(
'T'), ++out;
375 *out = Ch(
'Y'), ++out;
376 *out = Ch(
'P'), ++out;
377 *out = Ch(
'E'), ++out;
378 *out = Ch(
' '), ++out;
380 *out = Ch(
'>'), ++out;
385 template<
class OutIt,
class Ch>
386 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
389 if (!(flags & print_no_indenting))
390 out = fill_chars(out, indent, Ch(
'\t'));
391 *out = Ch(
'<'), ++out;
392 *out = Ch(
'?'), ++out;
394 *out = Ch(
' '), ++out;
396 *out = Ch(
'?'), ++out;
397 *out = Ch(
'>'), ++out;
412 template<
class OutIt,
class Ch>
415 return internal::print_node(out, &node, flags, 0);
418 #ifndef RAPIDXML_NO_STREAMS 426 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node,
int flags = 0)
428 print(std::ostream_iterator<Ch>(out), node, flags);
437 inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node)
439 return print(out, node);
This file contains rapidxml parser and DOM implementation.
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
A document node. Name and value are empty.
std::size_t value_size() const
An element node. Name contains element name. Value contains text of first data node.
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
A data node. Name is empty. Value contains data text.
A comment node. Name is empty. Value contains comment text.
A PI node. Name contains target. Value contains instructions.
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
const int print_no_indenting
Printer flag instructing the printer to suppress indenting of XML. See print() function.
A CDATA node. Name is empty. Value contains data text.
std::size_t name_size() const
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const