Attributes With CMarkup

 

comment posted attributes parsing

Tent Sergiu 16-Apr-2003

I have to parse a xml doc in which elements have random number of attributes and I don't know the names for these attributes. How can I get the number of attributes an element has?

See GetAttribName. In MFC, find the element, and then loop through the attributes as follows:

int nCount = 0;
while ( 1 )
{
  CString csName = xml.GetAttribName(nCount);
  if ( csName.IsEmpty() )
    break;
  CString csValue = xml.GetAttrib( csName );
  ++nCount;
}

 

comment posted EDOM - XML Attributes with empty string values

David Brue 23-Nov-2005

I am using CMarkup which is an EDOM implementation. In the documentation for the EDOM the function GetAttrib(...) is noted to return an empty string if the requested attribute does not exist. An XML attribute can still exist but have a value of the empty string. Does the EDOM provide any way to tell if an attribute exists but it set to the empty string? Examining the return value of GetAttrib(...) won't provide enough info... it could be missing altogether or it could be there but have an empty string value.

You are correct. It is a trade-off decision in the API. The only way to check if the attribute exists with an empty value is to iterate through GetAttribName(n) which allows you to see the names of all of the attributes of the particular element.