From e34acc39f93526e6ff9ade7539600539be6f5055 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 12 Aug 2015 00:02:47 +0200 Subject: Add support for querying current element, attribute --- xml/serializer | 16 ++++++++++++++-- xml/serializer.cxx | 26 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/xml/serializer b/xml/serializer index 0624634..ee5779b 100644 --- a/xml/serializer +++ b/xml/serializer @@ -240,7 +240,19 @@ namespace xml // the mapped prefix. // bool - lookup_namespace_prefix (const std::string& ns, std::string& prefix); + lookup_namespace_prefix (const std::string& ns, std::string& prefix) const; + + // Return the current element, that is, the latest element for which + // start_element() but not end_element() have been called. + // + qname + current_element () const; + + // Return the current attribute, that is, the latest attribute for + // which start_attribute() but not end_attribute() have been called. + // + qname + current_attribute () const; // Suspend/resume indentation. // @@ -268,7 +280,7 @@ namespace xml private: void - handle_error (genxStatus); + handle_error (genxStatus) const; private: std::ostream& os_; diff --git a/xml/serializer.cxx b/xml/serializer.cxx index df31b09..700243f 100644 --- a/xml/serializer.cxx +++ b/xml/serializer.cxx @@ -122,7 +122,7 @@ namespace xml } void serializer:: - handle_error (genxStatus e) + handle_error (genxStatus e) const { switch (e) { @@ -287,7 +287,7 @@ namespace xml } bool serializer:: - lookup_namespace_prefix (const string& ns, string& p) + lookup_namespace_prefix (const string& ns, string& p) const { // Currently Genx will create a namespace mapping if one doesn't // already exist. @@ -304,6 +304,28 @@ namespace xml return true; } + qname serializer:: + current_element () const + { + constUtf8 ns, n; + if (genxStatus e = genxGetCurrentElement (s_, &ns, &n)) + handle_error (e); + + return qname (ns != 0 ? reinterpret_cast (ns) : "", + reinterpret_cast (n)); + } + + qname serializer:: + current_attribute () const + { + constUtf8 ns, n; + if (genxStatus e = genxGetCurrentAttribute (s_, &ns, &n)) + handle_error (e); + + return qname (ns != 0 ? reinterpret_cast (ns) : "", + reinterpret_cast (n)); + } + void serializer:: suspend_indentation () { -- cgit v1.1