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);
132 template<
class OutIt,
class Ch>
133 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
136 switch (node->
type())
141 out = print_children(out, node, flags, indent);
146 out = print_element_node(out, node, flags, indent);
151 out = print_data_node(out, node, flags, indent);
156 out = print_cdata_node(out, node, flags, indent);
161 out = print_declaration_node(out, node, flags, indent);
166 out = print_comment_node(out, node, flags, indent);
171 out = print_doctype_node(out, node, flags, indent);
176 out = print_pi_node(out, node, flags, indent);
186 if (!(flags & print_no_indenting))
187 *out = Ch(
'\n'), ++out;
194 template<
class OutIt,
class Ch>
195 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
198 out = print_node(out, child, flags, indent);
203 template<
class OutIt,
class Ch>
204 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags)
208 if (attribute->name() && attribute->value())
211 *out = Ch(
' '), ++out;
212 out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
213 *out = Ch(
'='), ++out;
215 if (find_char<Ch, Ch(
'"')>(attribute->value(), attribute->value() + attribute->value_size()))
217 *out = Ch(
'\''), ++out;
218 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'"'), out);
219 *out = Ch(
'\''), ++out;
223 *out = Ch(
'"'), ++out;
224 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'\''), out);
225 *out = Ch(
'"'), ++out;
233 template<
class OutIt,
class Ch>
234 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
237 if (!(flags & print_no_indenting))
238 out = fill_chars(out, indent, Ch(
'\t'));
244 template<
class OutIt,
class Ch>
245 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
248 if (!(flags & print_no_indenting))
249 out = fill_chars(out, indent, Ch(
'\t'));
250 *out = Ch(
'<'); ++out;
251 *out = Ch(
'!'); ++out;
252 *out = Ch(
'['); ++out;
253 *out = Ch(
'C'); ++out;
254 *out = Ch(
'D'); ++out;
255 *out = Ch(
'A'); ++out;
256 *out = Ch(
'T'); ++out;
257 *out = Ch(
'A'); ++out;
258 *out = Ch(
'['); ++out;
260 *out = Ch(
']'); ++out;
261 *out = Ch(
']'); ++out;
262 *out = Ch(
'>'); ++out;
267 template<
class OutIt,
class Ch>
268 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
273 if (!(flags & print_no_indenting))
274 out = fill_chars(out, indent, Ch(
'\t'));
275 *out = Ch(
'<'), ++out;
277 out = print_attributes(out, node, flags);
283 *out = Ch(
'/'), ++out;
284 *out = Ch(
'>'), ++out;
289 *out = Ch(
'>'), ++out;
306 if (!(flags & print_no_indenting))
307 *out = Ch(
'\n'), ++out;
308 out = print_children(out, node, flags, indent + 1);
309 if (!(flags & print_no_indenting))
310 out = fill_chars(out, indent, Ch(
'\t'));
314 *out = Ch(
'<'), ++out;
315 *out = Ch(
'/'), ++out;
317 *out = Ch(
'>'), ++out;
323 template<
class OutIt,
class Ch>
324 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
327 if (!(flags & print_no_indenting))
328 out = fill_chars(out, indent, Ch(
'\t'));
329 *out = Ch(
'<'), ++out;
330 *out = Ch(
'?'), ++out;
331 *out = Ch(
'x'), ++out;
332 *out = Ch(
'm'), ++out;
333 *out = Ch(
'l'), ++out;
336 out = print_attributes(out, node, flags);
339 *out = Ch(
'?'), ++out;
340 *out = Ch(
'>'), ++out;
346 template<
class OutIt,
class Ch>
347 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
350 if (!(flags & print_no_indenting))
351 out = fill_chars(out, indent, Ch(
'\t'));
352 *out = Ch(
'<'), ++out;
353 *out = Ch(
'!'), ++out;
354 *out = Ch(
'-'), ++out;
355 *out = Ch(
'-'), ++out;
357 *out = Ch(
'-'), ++out;
358 *out = Ch(
'-'), ++out;
359 *out = Ch(
'>'), ++out;
364 template<
class OutIt,
class Ch>
365 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
368 if (!(flags & print_no_indenting))
369 out = fill_chars(out, indent, Ch(
'\t'));
370 *out = Ch(
'<'), ++out;
371 *out = Ch(
'!'), ++out;
372 *out = Ch(
'D'), ++out;
373 *out = Ch(
'O'), ++out;
374 *out = Ch(
'C'), ++out;
375 *out = Ch(
'T'), ++out;
376 *out = Ch(
'Y'), ++out;
377 *out = Ch(
'P'), ++out;
378 *out = Ch(
'E'), ++out;
379 *out = Ch(
' '), ++out;
381 *out = Ch(
'>'), ++out;
386 template<
class OutIt,
class Ch>
387 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
390 if (!(flags & print_no_indenting))
391 out = fill_chars(out, indent, Ch(
'\t'));
392 *out = Ch(
'<'), ++out;
393 *out = Ch(
'?'), ++out;
395 *out = Ch(
' '), ++out;
397 *out = Ch(
'?'), ++out;
398 *out = Ch(
'>'), ++out;
413 template<
class OutIt,
class Ch>
416 return internal::print_node(out, &node, flags, 0);
419 #ifndef RAPIDXML_NO_STREAMS 427 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node,
int flags = 0)
429 print(std::ostream_iterator<Ch>(out), node, flags);
438 inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node)
440 return print(out, node);
This file contains rapidxml parser and DOM implementation.
A comment node. Name is empty. Value contains comment text.
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.
An element node. Name contains element name. Value contains text of first data node.
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
Printer flag instructing the printer to suppress indenting of XML. See print() function.
A data node. Name is empty. Value contains data text.
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
A PI node. Name contains target. Value contains instructions.
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
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