From fec681be83c91268ee4db97f34ce4e47179316dd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 8 May 2014 17:50:12 -0700 Subject: Add helpers for serializing elements with simple content --- xml/serializer.cxx | 7 +++++++ xml/serializer.hxx | 36 ++++++++++++++++++++++++++++++++++++ xml/serializer.ixx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) (limited to 'xml') diff --git a/xml/serializer.cxx b/xml/serializer.cxx index 8147f91..a6afcca 100644 --- a/xml/serializer.cxx +++ b/xml/serializer.cxx @@ -173,6 +173,13 @@ namespace xml } void serializer:: + element (const string& ns, const string& n, const string& v) + { + start_element (ns, n); + element (v); + } + + void serializer:: start_attribute (const string& ns, const string& name) { if (genxStatus e = genxStartAttributeLiteral ( diff --git a/xml/serializer.hxx b/xml/serializer.hxx index e0041f9..d07221d 100644 --- a/xml/serializer.hxx +++ b/xml/serializer.hxx @@ -94,6 +94,42 @@ namespace xml void end_element (); + // Helpers for serializing elements with simple content. The first two + // functions assume that start_element() has already been called. The + // other two serialize the complete element, from start to end. + // + void + element (const std::string& value); + + template + void + element (const T& value); + + void + element (const std::string& name, const std::string& value); + + template + void + element (const std::string& name, const T& value); + + void + element (const qname_type& qname, const std::string& value); + + template + void + element (const qname_type& qname, const T& value); + + void + element (const std::string& namespace_, + const std::string& name, + const std::string& value); + + template + void + element (const std::string& namespace_, + const std::string& name, + const T& value); + // Attributes. // void diff --git a/xml/serializer.ixx b/xml/serializer.ixx index d329bbd..81631f2 100644 --- a/xml/serializer.ixx +++ b/xml/serializer.ixx @@ -19,6 +19,55 @@ namespace xml } inline void serializer:: + element (const std::string& v) + { + if (!v.empty ()) + characters (v); + + end_element (); + } + + template + inline void serializer:: + element (const T& v) + { + element (value_traits::serialize (v, *this)); + } + + inline void serializer:: + element (const std::string& n, const std::string& v) + { + element (std::string (), n, v); + } + + template + inline void serializer:: + element (const std::string& n, const T& v) + { + element (n, value_traits::serialize (v, *this)); + } + + inline void serializer:: + element (const qname_type& qn, const std::string& v) + { + element (qn.namespace_ (), qn.name (), v); + } + + template + inline void serializer:: + element (const qname_type& qn, const T& v) + { + element (qn, value_traits::serialize (v, *this)); + } + + template + inline void serializer:: + element (const std::string& ns, const std::string& n, const T& v) + { + element (ns, n, value_traits::serialize (v, *this)); + } + + inline void serializer:: start_attribute (const qname_type& qname) { start_attribute (qname.namespace_ (), qname.name ()); -- cgit v1.1