Download C++/Tree Mapping User Manual

Transcript
2.8.4 Element Order
n.push_back ("one");
n.push_back ("two");
o.member (n);
// deep copy
}
2.8.4 Element Order
C++/Tree is a "flattening" mapping in a sense that many levels of nested compositors (choice
and sequence), all potentially with their own cardinalities, are in the end mapped to a flat set of
elements with one of the three cardinality classes discussed in the previous sections. While this
results in a simple and easy to use API for most types, in certain cases, the order of elements in
the actual XML documents is not preserved once parsed into the object model. And sometimes
such order has application-specific significance. As an example, consider a schema that defines a
batch of bank transactions:
<complexType name="withdraw">
<sequence>
<element name="account" type="unsignedInt"/>
<element name="amount" type="unsignedInt"/>
</sequence>
</complexType>
<complexType name="deposit">
<sequence>
<element name="account" type="unsignedInt"/>
<element name="amount" type="unsignedInt"/>
</sequence>
</complexType>
<complexType name="batch">
<choice minOccurs="0" maxOccurs="unbounded">
<element name="withdraw" type="withdraw"/>
<element name="deposit" type="deposit"/>
</choice>
</complexType>
The batch can contain any number of transactions in any order but the order of transactions in
each actual batch is significant. For instance, consider what could happen if we reorder the transactions and apply all the withdrawals before deposits.
For the batch schema type defined above the default C++/Tree mapping will produce a C++
class that contains a pair of sequence containers, one for each of the two elements. While this will
capture the content (transactions), the order of this content as it appears in XML will be lost.
Also, if we try to serialize the batch we just loaded back to XML, all the withdrawal transactions
will appear before deposits.
48
C++/Tree Mapping User Manual, v4.0.0
July 2014