Manipulating XML Content in C++
This example adds a new item to the purchase order instance that was unmarshaled before marshaling it back out.
The purchase order schema defines a type called Items which has a child element named item of type Item, which can occur an unlimited number of times. HydraExpress maps this definition to an std::vector of the type Item. A typedef on the Items class is generated with the type name concatenated with the word Vector, which can be used to reference the vector type.
The code below illustrates how this collection can be used to add a new toaster to the purchase order. First get the old list and store a copy of it to the local variable named itemVector, as shown here:
// Manipulate the object hierarchy by adding an additional item
// to the existing list of items
Items::ItemsItemVector & itemVector = po.getItems().getItemsItemVector();
Then create a new item that represents a toaster to purchase, and set the details that correspond to that toaster:
// Create the new toaster item
ItemsItem toaster;
toaster.setProductName("Toaster Oven");
toaster.setShipDate(RWDate(19, 5, 1999));
toaster.setComment("Four slice model");
Append this new item to the item vector before creating the new Items instance that was defined in the purchase order schema. The only member on the Items instance is an item vector, which you set to the modified vector instance, as shown here:
// Add it to the vector