SSS - S3 Toolkit 0.9.6
S3 client library and applications
Loading...
Searching...
No Matches
XMLOStream Class Reference

XMLGenerator. Use methods or overloaded subscript operator to insert data into XML tree. More...

#include <xmlstreams.h>

Public Types

enum  MoveAction
 Move up or down one level in tree or rewind to root.
 

Public Member Functions

void Up (int level=1)
 
void Down ()
 
void Rewind ()
 Move pointer to current node to root.
 
XMLOStreamInsertText (const std::string &text)
 
XMLOStreamInsert (const std::string &s)
 
XMLOStreamMove (MoveAction a, int level=1)
 
XMLOStreamoperator[] (const std::string &s)
 
XMLOStreamoperator[] (MoveAction a)
 Invoke Insert(MoveAction) method.
 
 XMLOStream (tinyxml2::XMLDocument &d)
 
XMLOStreamoperator= (const std::string &s)
 
std::string XMLText () const
 
const tinyxml2::XMLDocument & GetDocument () const
 

Detailed Description

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;
XMLOStream os(doc);
os["accesscontrolpolicy/accesscontrollist"];
if (!acl.ownerDisplayName.empty() || !acl.ownerID.empty()) {
os["owner"]; // <accesscontrolpolicy><accesscontrollist><owner>
if (!acl.ownerDisplayName.empty()) {
//<accesscontrolpolicy><accesscontrollist><owner><displayname>
os["displayname"] = acl.ownerDisplayName;
//</displayname> automatically move to upper level after assignment
}
if (!acl.ownerID.empty()) {
//<accesscontrolpolicy><accesscontrollist><owner><ownerid>
os["ownerid"] = acl.ownerDisplayName;
//</ownerid> automatically move to upper level after assignment
}
os["/"]; // </owner>
}
for (const auto &g : acl.grants) {
if (g.permission.empty()) {
throw logic_error("Missing required field 'permission'");
}
os["grant"]; // <grant>
const Grant::Grantee &i = g.grantee;
if (!i.Empty()) {
os["grantee"]; // <grant><grantee>
if (!i.displayName.empty()) {
// <grant><grantee><displayname>
os["displayname"] = i.displayName;
// </displayname>
}
if (!i.emailAddress.empty()) {
// <grant><grantee><emailaddress>
os["emailaddress"] = i.emailAddress;
// </emailaddress>
}
if (!i.id.empty()) {
// <grant><grantee><id>
os["id"] = i.id;
// </id>
}
if (!i.xsiType.empty()) {
// <grant><grantee><type>``
os["type"] = i.xsiType;
// </type>
}
if (!i.uri.empty()) {
// <grant><grantee><uri>
os["uri"] = i.uri;
// <uri>
}
}
os["/"] // </grantee>
// <grant><permission>
["permission"] = g.permission;
// </permission>
}
return os.XMLText();
}
XMLGenerator. Use methods or overloaded subscript operator to insert data into XML tree.
Definition xmlstreams.h:125

Constructor & Destructor Documentation

◆ XMLOStream()

XMLOStream::XMLOStream ( tinyxml2::XMLDocument &  d)
inline

Constructor: requires a reference to a pre-existing XML document.

Parameters
[in]dwrapped XML document

Member Function Documentation

◆ Down()

void XMLOStream::Down ( )
inline

Move down after setting text Set down_ flag: pointer to current node will be moved to child after next insertion

+ Here is the caller graph for this function:

◆ GetDocument()

const tinyxml2::XMLDocument & XMLOStream::GetDocument ( ) const
inline
Returns
reference to current document

◆ Insert()

XMLOStream & XMLOStream::Insert ( const std::string &  s)
inline

Insert XML element under current XML element.

Parameters
[in]stag name
Returns
reference to current XMLOStream instance
+ Here is the caller graph for this function:

◆ InsertText()

XMLOStream & XMLOStream::InsertText ( const std::string &  text)
inline

Insert text inside current element.

Parameters
[in]texttext to insert
Returns
reference to current XMLOStream instance, will return without inserting in case current pointer to XML element is NULL
+ Here is the caller graph for this function:

◆ Move()

XMLOStream & XMLOStream::Move ( MoveAction  a,
int  level = 1 
)
inline

Move pointer to XML element.

See also
MoveAction In the case of REWIND or UP the action is executed immediately in case of DOWN it is executed after next insertion operation

References Down(), Rewind(), and Up().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

XMLOStream & XMLOStream::operator= ( const std::string &  s)
inline

Add text element to current XML element and move up one level.

Parameters
[in]stext to insert
Returns
reference to XMLOStream instance

References InsertText(), and Up().

+ Here is the call graph for this function:

◆ operator[]()

XMLOStream & XMLOStream::operator[] ( const std::string &  s)
inline

Invokes insert method forcing DOWN action after insert. In case only path separator ('/') elements are provided the UP action is invoked as many times as there are '/' caracters in the string.

References Insert(), and Up().

+ Here is the call graph for this function:

◆ Up()

void XMLOStream::Up ( int  level = 1)
inline

Move up

Parameters
[in]levelnumber of parents to traverse, default is one
+ Here is the caller graph for this function:

◆ XMLText()

std::string XMLOStream::XMLText ( ) const
inline
Returns
current content of XML document as XML text

References XMLToText().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: