aboutsummaryrefslogtreecommitdiff
path: root/xml/parser.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-05-08 17:02:55 -0700
committerBoris Kolpackov <boris@codesynthesis.com>2014-05-08 17:02:55 -0700
commita6e24513d89067c16a3df214a7e2679e1f1675f1 (patch)
treeb622213d673b73005bcd6002e67b121714c9c55b /xml/parser.cxx
parent8234b273aea9a662b8675190d3e73c90ce159f1a (diff)
Add helpers for parsing elements with simple content
Diffstat (limited to 'xml/parser.cxx')
-rw-r--r--xml/parser.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/xml/parser.cxx b/xml/parser.cxx
index d9d2fcb..6d5ab23 100644
--- a/xml/parser.cxx
+++ b/xml/parser.cxx
@@ -283,6 +283,42 @@ namespace xml
qname_type (ns, n).string () + "' expected");
}
+ string parser::
+ element ()
+ {
+ content (simple);
+ string r;
+
+ // The content of the element can be empty in which case there
+ // will be no characters event.
+ //
+ event_type e (next ());
+ if (e == characters)
+ {
+ r.swap (value ());
+ e = next ();
+ }
+
+ // We cannot really get anything other than end_element since
+ // the simple content validation won't allow it.
+ //
+ assert (e == end_element);
+
+ return r;
+ }
+
+ string parser::
+ element (const qname_type& qn, const string& dv)
+ {
+ if (peek () == start_element && qname () == qn)
+ {
+ next ();
+ return element ();
+ }
+
+ return dv;
+ }
+
const parser::element_entry* parser::
get_element_ () const
{