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);
106 template<
class OutIt,
class Ch>
107 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
108 template<
class OutIt,
class Ch>
109 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
110 template<
class OutIt,
class Ch>
111 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
112 template<
class OutIt,
class Ch>
113 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
114 template<
class OutIt,
class Ch>
115 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
116 template<
class OutIt,
class Ch>
117 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
118 template<
class OutIt,
class Ch>
119 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent);
123 template<
class OutIt,
class Ch>
124 inline OutIt print_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
127 switch (node->
type())
132 out = print_children(out, node, flags, indent);
137 out = print_element_node(out, node, flags, indent);
142 out = print_data_node(out, node, flags, indent);
147 out = print_cdata_node(out, node, flags, indent);
152 out = print_declaration_node(out, node, flags, indent);
157 out = print_comment_node(out, node, flags, indent);
162 out = print_doctype_node(out, node, flags, indent);
167 out = print_pi_node(out, node, flags, indent);
177 if (!(flags & print_no_indenting))
178 *out = Ch(
'\n'), ++out;
185 template<
class OutIt,
class Ch>
186 inline OutIt print_children(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
189 out = print_node(out, child, flags, indent);
194 template<
class OutIt,
class Ch>
195 inline OutIt print_attributes(OutIt out,
const xml_node<Ch> *node,
int flags)
199 if (attribute->name() && attribute->value())
202 *out = Ch(
' '), ++out;
203 out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
204 *out = Ch(
'='), ++out;
206 if (find_char<Ch, Ch(
'"')>(attribute->value(), attribute->value() + attribute->value_size()))
208 *out = Ch(
'\''), ++out;
209 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'"'), out);
210 *out = Ch(
'\''), ++out;
214 *out = Ch(
'"'), ++out;
215 out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch(
'\''), out);
216 *out = Ch(
'"'), ++out;
224 template<
class OutIt,
class Ch>
225 inline OutIt print_data_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
228 if (!(flags & print_no_indenting))
229 out = fill_chars(out, indent, Ch(
'\t'));
235 template<
class OutIt,
class Ch>
236 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
239 if (!(flags & print_no_indenting))
240 out = fill_chars(out, indent, Ch(
'\t'));
241 *out = Ch(
'<'); ++out;
242 *out = Ch(
'!'); ++out;
243 *out = Ch(
'['); ++out;
244 *out = Ch(
'C'); ++out;
245 *out = Ch(
'D'); ++out;
246 *out = Ch(
'A'); ++out;
247 *out = Ch(
'T'); ++out;
248 *out = Ch(
'A'); ++out;
249 *out = Ch(
'['); ++out;
251 *out = Ch(
']'); ++out;
252 *out = Ch(
']'); ++out;
253 *out = Ch(
'>'); ++out;
258 template<
class OutIt,
class Ch>
259 inline OutIt print_element_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
264 if (!(flags & print_no_indenting))
265 out = fill_chars(out, indent, Ch(
'\t'));
266 *out = Ch(
'<'), ++out;
268 out = print_attributes(out, node, flags);
274 *out = Ch(
'/'), ++out;
275 *out = Ch(
'>'), ++out;
280 *out = Ch(
'>'), ++out;
297 if (!(flags & print_no_indenting))
298 *out = Ch(
'\n'), ++out;
299 out = print_children(out, node, flags, indent + 1);
300 if (!(flags & print_no_indenting))
301 out = fill_chars(out, indent, Ch(
'\t'));
305 *out = Ch(
'<'), ++out;
306 *out = Ch(
'/'), ++out;
308 *out = Ch(
'>'), ++out;
314 template<
class OutIt,
class Ch>
315 inline OutIt print_declaration_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
318 if (!(flags & print_no_indenting))
319 out = fill_chars(out, indent, Ch(
'\t'));
320 *out = Ch(
'<'), ++out;
321 *out = Ch(
'?'), ++out;
322 *out = Ch(
'x'), ++out;
323 *out = Ch(
'm'), ++out;
324 *out = Ch(
'l'), ++out;
327 out = print_attributes(out, node, flags);
330 *out = Ch(
'?'), ++out;
331 *out = Ch(
'>'), ++out;
337 template<
class OutIt,
class Ch>
338 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
341 if (!(flags & print_no_indenting))
342 out = fill_chars(out, indent, Ch(
'\t'));
343 *out = Ch(
'<'), ++out;
344 *out = Ch(
'!'), ++out;
345 *out = Ch(
'-'), ++out;
346 *out = Ch(
'-'), ++out;
348 *out = Ch(
'-'), ++out;
349 *out = Ch(
'-'), ++out;
350 *out = Ch(
'>'), ++out;
355 template<
class OutIt,
class Ch>
356 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
359 if (!(flags & print_no_indenting))
360 out = fill_chars(out, indent, Ch(
'\t'));
361 *out = Ch(
'<'), ++out;
362 *out = Ch(
'!'), ++out;
363 *out = Ch(
'D'), ++out;
364 *out = Ch(
'O'), ++out;
365 *out = Ch(
'C'), ++out;
366 *out = Ch(
'T'), ++out;
367 *out = Ch(
'Y'), ++out;
368 *out = Ch(
'P'), ++out;
369 *out = Ch(
'E'), ++out;
370 *out = Ch(
' '), ++out;
372 *out = Ch(
'>'), ++out;
377 template<
class OutIt,
class Ch>
378 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch> *node,
int flags,
int indent)
381 if (!(flags & print_no_indenting))
382 out = fill_chars(out, indent, Ch(
'\t'));
383 *out = Ch(
'<'), ++out;
384 *out = Ch(
'?'), ++out;
386 *out = Ch(
' '), ++out;
388 *out = Ch(
'?'), ++out;
389 *out = Ch(
'>'), ++out;
404 template<
class OutIt,
class Ch>
407 return internal::print_node(out, &node, flags, 0);
410 #ifndef RAPIDXML_NO_STREAMS 418 inline std::basic_ostream<Ch> &
print(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node,
int flags = 0)
420 print(std::ostream_iterator<Ch>(out), node, flags);
429 inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,
const xml_node<Ch> &node)
431 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.
EIGEN_STRONG_INLINE iterator begin()
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