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)
106 template<
class OutIt,
class Ch>
107 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
110 switch (node->
type())
115 out = print_children(out, node, flags, indent);
120 out = print_element_node(out, node, flags, indent);
125 out = print_data_node(out, node, flags, indent);
130 out = print_cdata_node(out, node, flags, indent);
135 out = print_declaration_node(out, node, flags, indent);
140 out = print_comment_node(out, node, flags, indent);
145 out = print_doctype_node(out, node, flags, indent);
150 out = print_pi_node(out, node, flags, indent);
160 if (!(flags & print_no_indenting))
161 *out = Ch(
'\n'), ++out;
168 template<
class OutIt,
class Ch>
169 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
172 out = print_node(out, child, flags, indent);
177 template<
class OutIt,
class Ch>
178 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags)
182 if (attribute->name() && attribute->value())
185 *out = Ch(
' '), ++out;
186 out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
187 *out = Ch(
'='), ++out;
189 if (find_char<Ch, Ch(
'"')>(attribute->value(), attribute->value() + attribute->value_size()))
191 *out = Ch(
'\''), ++out;
192 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'"'), out);
193 *out = Ch(
'\''), ++out;
197 *out = Ch(
'"'), ++out;
198 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'\''), out);
199 *out = Ch(
'"'), ++out;
207 template<
class OutIt,
class Ch>
208 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
211 if (!(flags & print_no_indenting))
212 out = fill_chars(out, indent, Ch(
'\t'));
218 template<
class OutIt,
class Ch>
219 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
222 if (!(flags & print_no_indenting))
223 out = fill_chars(out, indent, Ch(
'\t'));
224 *out = Ch(
'<'); ++out;
225 *out = Ch(
'!'); ++out;
226 *out = Ch(
'['); ++out;
227 *out = Ch(
'C'); ++out;
228 *out = Ch(
'D'); ++out;
229 *out = Ch(
'A'); ++out;
230 *out = Ch(
'T'); ++out;
231 *out = Ch(
'A'); ++out;
232 *out = Ch(
'['); ++out;
234 *out = Ch(
']'); ++out;
235 *out = Ch(
']'); ++out;
236 *out = Ch(
'>'); ++out;
241 template<
class OutIt,
class Ch>
242 inline OutIt print_element_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;
251 out = print_attributes(out, node, flags);
257 *out = Ch(
'/'), ++out;
258 *out = Ch(
'>'), ++out;
263 *out = Ch(
'>'), ++out;
280 if (!(flags & print_no_indenting))
281 *out = Ch(
'\n'), ++out;
282 out = print_children(out, node, flags, indent + 1);
283 if (!(flags & print_no_indenting))
284 out = fill_chars(out, indent, Ch(
'\t'));
288 *out = Ch(
'<'), ++out;
289 *out = Ch(
'/'), ++out;
291 *out = Ch(
'>'), ++out;
297 template<
class OutIt,
class Ch>
298 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
301 if (!(flags & print_no_indenting))
302 out = fill_chars(out, indent, Ch(
'\t'));
303 *out = Ch(
'<'), ++out;
304 *out = Ch(
'?'), ++out;
305 *out = Ch(
'x'), ++out;
306 *out = Ch(
'm'), ++out;
307 *out = Ch(
'l'), ++out;
310 out = print_attributes(out, node, flags);
313 *out = Ch(
'?'), ++out;
314 *out = Ch(
'>'), ++out;
320 template<
class OutIt,
class Ch>
321 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
324 if (!(flags & print_no_indenting))
325 out = fill_chars(out, indent, Ch(
'\t'));
326 *out = Ch(
'<'), ++out;
327 *out = Ch(
'!'), ++out;
328 *out = Ch(
'-'), ++out;
329 *out = Ch(
'-'), ++out;
331 *out = Ch(
'-'), ++out;
332 *out = Ch(
'-'), ++out;
333 *out = Ch(
'>'), ++out;
338 template<
class OutIt,
class Ch>
339 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
342 if (!(flags & print_no_indenting))
343 out = fill_chars(out, indent, Ch(
'\t'));
344 *out = Ch(
'<'), ++out;
345 *out = Ch(
'!'), ++out;
346 *out = Ch(
'D'), ++out;
347 *out = Ch(
'O'), ++out;
348 *out = Ch(
'C'), ++out;
349 *out = Ch(
'T'), ++out;
350 *out = Ch(
'Y'), ++out;
351 *out = Ch(
'P'), ++out;
352 *out = Ch(
'E'), ++out;
353 *out = Ch(
' '), ++out;
355 *out = Ch(
'>'), ++out;
360 template<
class OutIt,
class Ch>
361 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
364 if (!(flags & print_no_indenting))
365 out = fill_chars(out, indent, Ch(
'\t'));
366 *out = Ch(
'<'), ++out;
367 *out = Ch(
'?'), ++out;
369 *out = Ch(
' '), ++out;
371 *out = Ch(
'?'), ++out;
372 *out = Ch(
'>'), ++out;
387 template<
class OutIt,
class Ch>
390 return internal::print_node(out, &node, flags, 0);
393 #ifndef RAPIDXML_NO_STREAMS 401 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node,
int flags = 0)
403 print(std::ostream_iterator<Ch>(out), node, flags);
412 inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node)
414 return print(out, node);
This file contains rapidxml parser and DOM implementation.
A comment node. Name is empty. Value contains comment text.
Definition: rapidxml.hpp:149
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Definition: rapidxml_print.hpp:388
Ch * value() const
Definition: rapidxml.hpp:692
std::size_t name_size() const
Definition: rapidxml.hpp:681
A CDATA node. Name is empty. Value contains data text.
Definition: rapidxml.hpp:148
An element node. Name contains element name. Value contains text of first data node.
Definition: rapidxml.hpp:146
A document node. Name and value are empty.
Definition: rapidxml.hpp:145
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:936
node_type type() const
Definition: rapidxml.hpp:913
Ch * name() const
Definition: rapidxml.hpp:673
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
const int print_no_indenting
Printer flag instructing the printer to suppress indenting of XML. See print() function.
Definition: rapidxml_print.hpp:23
Definition: rapidxml.hpp:138
A data node. Name is empty. Value contains data text.
Definition: rapidxml.hpp:147
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
Definition: rapidxml.hpp:151
A PI node. Name contains target. Value contains instructions.
Definition: rapidxml.hpp:152
A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalon...
Definition: rapidxml.hpp:150
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1004
Definition: rapidxml.hpp:137
Definition: rapidxml.hpp:57
std::size_t value_size() const
Definition: rapidxml.hpp:700