XMLGenerator. Use methods or overloaded subscript operator to insert data into XML tree.
More...
XMLGenerator. Use methods or overloaded subscript operator to insert data into XML tree.
A XML document object and a pointer to the current XML Element are maintained inside the class instance. Elements are added under the current element. The current element pointer can be moved up or down the tree as needed. The generated XML code is extracted by calling the XMLText method.
Example
Generating the ACL request body.
Request format:
<AccessControlPolicy>
<Owner>
<DisplayName>string</DisplayName>
<ID>string</ID>
</Owner>
<AccessControlList>
<Grant>
<Grantee>
<DisplayName>string</DisplayName>
<EmailAddress>string</EmailAddress>
<ID>string</ID>
<xsi:type>string</xsi:type>
<URI>string</URI>
</Grantee>
<Permission>string</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>
Code:
std::string GenerateAclXML(const AccessControlPolicy &acl) {
XMLDocument doc;
os["accesscontrolpolicy/accesscontrollist"];
if (!acl.ownerDisplayName.empty() || !acl.ownerID.empty()) {
os["owner"];
if (!acl.ownerDisplayName.empty()) {
os["displayname"] = acl.ownerDisplayName;
}
if (!acl.ownerID.empty()) {
os["ownerid"] = acl.ownerDisplayName;
}
os["/"];
}
for (const auto &g : acl.grants) {
if (g.permission.empty()) {
throw logic_error("Missing required field 'permission'");
}
os["grant"];
const Grant::Grantee &i = g.grantee;
if (!i.Empty()) {
os["grantee"];
if (!i.displayName.empty()) {
os["displayname"] = i.displayName;
}
if (!i.emailAddress.empty()) {
os["emailaddress"] = i.emailAddress;
}
if (!i.id.empty()) {
os["id"] = i.id;
}
if (!i.xsiType.empty()) {
os["type"] = i.xsiType;
}
if (!i.uri.empty()) {
os["uri"] = i.uri;
}
}
os["/"]
["permission"] = g.permission;
}
return os.XMLText();
}
XMLGenerator. Use methods or overloaded subscript operator to insert data into XML tree.
Definition xmlstreams.h:125