CMarkup AddElem Method

bool CMarkup::AddElem( MCD_CSTR szName, MCD_CSTR szData = NULL, int nFlags = 0 );
bool CMarkup::AddElem( MCD_CSTR szName, int nValue, int nFlags = 0 );

The AddElem method is called to add an element after the main position (see InsertElem to put it before the main position). This should be the first method used on the newly instantiated CMarkup object to create the root element. After calling IntoElem you can add an element inside the root element.

CMarkup xml;
xml.AddElem( "LIST" ); // root element
xml.AddElem( "ITEM", "A" );
xml.AddElem( "ITEM", "B" );

You can also use it inside the document to add elements under the current parent position. If there is no main position, the element is added as the last element under the current parent position. After an element is successfully added, the main position points to the new element and there is no child position.

The data value is optional. If no data value or an empty string is specified, an empty element is created. The method returns true if the element is added successfully and the main position points to it.

The following flags can be used when adding or inserting an element with AddElem, InsertElem, AddChildElem and InsertChildElem.

Flag Purpose
MNF_WITHCDATA encode the data value as a CDATA Section
MNF_WITHREFS in the data value, do not escape the leading ampersand of entity references and numeric character references
MNF_WITHNOLINES no end of line (EOL) characters will be added before or after the new element
MNF_WITHNOEND create an element without an end tag
MNF_WITHXHTMLSPACE put a space before the slash in the empty element tag (e.g. <br />), an empty string "" must be supplied for the data argument

Update March 24, 2009: AddElem can be used with CMarkup release 11.0 developer version file write mode (see C++ XML writer).