aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-08-12 00:02:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-08-12 00:02:47 +0200
commite34acc39f93526e6ff9ade7539600539be6f5055 (patch)
tree239ff235a34828fd6c79537509bcc598a30d189a
parent503cd7a8cbb54719db115391de17ec265ea2b543 (diff)
Add support for querying current element, attribute
-rw-r--r--xml/serializer16
-rw-r--r--xml/serializer.cxx26
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<const char*> (ns) : "",
+ reinterpret_cast<const char*> (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<const char*> (ns) : "",
+ reinterpret_cast<const char*> (n));
+ }
+
void serializer::
suspend_indentation ()
{