From be6559e090455206c66d1cb7e65a2e4f34a61861 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 May 2014 11:34:05 -0700 Subject: Add 'hybrid' example --- examples/hybrid/dom.hxx | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/hybrid/dom.hxx (limited to 'examples/hybrid/dom.hxx') diff --git a/examples/hybrid/dom.hxx b/examples/hybrid/dom.hxx new file mode 100644 index 0000000..3e1f8e3 --- /dev/null +++ b/examples/hybrid/dom.hxx @@ -0,0 +1,72 @@ +// file : examples/hybrid/dom.hxx +// copyright : not copyrighted - public domain + +#ifndef DOM_HXX +#define DOM_HXX + +#include +#include +#include + +#include +#include + +// A simple, DOM-like in-memory representation of raw XML. It only supports +// empty, simple, and complex content (no mixed content) and is not +// particularly efficient, at least not in C++98. + +class element; +typedef std::map attributes; +typedef std::vector elements; + +class element +{ +public: + typedef ::attributes attributes_type; + typedef ::elements elements_type; + + element (const xml::qname& name): name_ (name) {} + element (const xml::qname& name, const std::string text) + : name_ (name), text_ (text) {} + + const xml::qname& + name () const {return name_;} + + const attributes_type& + attributes () const {return attributes_;} + + attributes_type& + attributes () {return attributes_;} + + const std::string& + text () const {return text_;} + + void + text (const std::string& text) {text_ = text;} + + const elements_type& + elements () const {return elements_;} + + elements_type& + elements () {return elements_;} + +public: + // Parse an element. If start_end is false, then don't parse the + // start and end of the element. + // + element (xml::parser&, bool start_end = true); + + // Serialize an element. If start_end is false, then don't serialize + // the start and end of the element. + // + void + serialize (xml::serializer&, bool start_end = true) const; + +private: + xml::qname name_; + attributes_type attributes_; + std::string text_; // Simple content only. + elements_type elements_; // Complex content only. +}; + +#endif // DOM_HXX -- cgit v1.1