aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/evolution/passthrough/unknown-type-simpl.cxx
blob: 426da5faeac02b6d9020078ba110e09c2937a362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// file      : examples/cxx/hybrid/evolution/passthrough/unknown-type-simpl.cxx
// copyright : not copyrighted - public domain

// Include transform-simpl.hxx (which includes unknown-type-simpl.hxx)
// instead of unknown-type-simpl.hxx.
//
#include "transform-simpl.hxx"

namespace transform
{
  void unknown_type_simpl::
  _serialize_attributes ()
  {
    // Allow the base to serialize its attributes.
    //
    unknown_type_base_simpl::_serialize_attributes ();

    // Serialize attributes from the unknown content.
    //
    const xml::element& e =
      unknown_type_base_simpl_state_.unknown_type_->content ();

    serialize (e.attributes ());
  }

  void unknown_type_simpl::
  _serialize_content ()
  {
    // Allow the base to serialize its elements.
    //
    unknown_type_base_simpl::_serialize_content ();

    // Serialize elements from the unknown content.
    //
    const xml::element& e =
      unknown_type_base_simpl_state_.unknown_type_->content ();

    serialize (e.children ());
  }

  void unknown_type_simpl::
  serialize (const xml::attributes& as)
  {
    for (xml::attributes::const_iterator i (as.begin ()); i != as.end (); ++i)
    {
      const xml::qname& n = i->first;
      const std::string& v = i->second;

      if (n.ns ().empty ())
        _attribute (n.name ().c_str (), v.c_str ());
      else
        _attribute (n.ns ().c_str (), n.name ().c_str (), v.c_str ());
    }
  }

  void unknown_type_simpl::
  serialize (const xml::elements& es)
  {
    for (xml::elements::const_iterator i (es.begin ()); i != es.end (); ++i)
    {
      const xml::element& e = **i;
      const xml::qname& n = e.name ();

      if (n.ns ().empty ())
        _start_element (n.name ().c_str ());
      else
        _start_element (n.ns ().c_str (), n.name ().c_str ());

      serialize (e.attributes ());

      if (!e.children ().empty ())
        serialize (e.children ());
      else if (!e.value ().empty ())
        _characters (e.value ().c_str ());

      _end_element ();
    }
  }
}