bool CMarkup::SetAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue, int nFlags = 0 );
bool CMarkup::SetAttrib( MCD_CSTR szAttrib, int nValue, int nFlags = 0 );

Calling SetAttrib adds or changes the attribute named szAttrib in the main position element to have the specified value. If the attribute already exists for the main position element, the value is changed. Otherwise the attribute and its value are added. The method returns false if there is no main position element.

CMarkup xml;
xml.AddElem( "ROOT" );
xml.SetAttrib( "customcode", 35 );
<ROOT customcode="35"/>

SetAttrib also works when the main position is a processing instruction node. See Node Methods in CMarkup.

Update September 27, 2008: In CMarkup release 10.0 you can specify MNF_WITHREFS in the optional nFlags argument to set an attribute value with numeric character references or entities. This tells CMarkup not to double escape ampersands that are followed by an entity name or numeric character reference and semi-colon. Here is an example setting the attribute with an escaped ampersand in the href attribute of an HTML hyperlink.

html.SetAttrib( "href",
  ";b=2", CMarkup::MNF_WITHREFS );

The AddAttrib method is no longer used and was the same as SetAttrib. The term "Add" is misleading because an element can only have one attribute of a given name.

See also: