CMarkup HasAttrib Method

bool CMarkup::HasAttrib( MCD_CSTR szAttrib, MCD_STR* pstrValue = NULL ) const;

CMarkup Developer License

HasAttrib is only in CMarkup Developer and the free XML editor  FOAL C++ scripting.

Call HasAttrib to find out if the specified attribute exists in the current main position element. Since the GetAttrib method returns an empty string whether the element has the attribute with an empty value or does not have the attribute. This method is useful to distinguish whether the element has the attribute at all.

This will return true even if the specified attribute value is empty!

<example name=""/>
CMarkup xml( "<example name=\"\"/>" );
xml.FindElem();
MCD_STR strName = xml.GetAttrib( "name" ); // empty string
bool bHasNameAttrib = xml.HasAttrib( "name" ); // true

Update February 5, 2011: With release 11.4, use the optional pstrValue argument to retrieve the attribute value. Now you can use HasAttrib instead of GetAttrib to get an attribute value at the same time as discovering whether the attribute exists:

MCD_STR strName;
if ( xml.HasAttrib("name",&strName) )
{
  // use attribute value...

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