Compartilhar via


IsDefault

 

Indicates whether the attribute was specified in the source document or implied by the Document Type Definition (DTD).

Syntax

  
BOOL IsDefault ();  

Return Value

Returns TRUE if the attribute was implied by the DTD. If the attribute was not implied by the DTD, or the node is not an attribute, returns FALSE.

Remarks

Because DTDs allow only attributes to be defined with defaults, this property is TRUE only for attribute nodes.

The following code writes all attributes where IsDefault returns FALSE:

HRESULT WriteAttributes(IXmlReader* pReader)  
{  
    const WCHAR* pwszPrefix;  
    const WCHAR* pwszLocalName;  
    const WCHAR* pwszValue;  
    HRESULT hr = pReader->MoveToFirstAttribute();  
  
    if (S_FALSE == hr)  
        return hr;  
    if (S_OK != hr)  
    {  
        wprintf(L"Error moving to first attribute, error is %08.8lx", hr);  
        return -1;  
    }  
    else  
    {  
        while (TRUE)  
        {  
            if (!pReader->IsDefault())  
            {  
                UINT cwchPrefix;  
                if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix)))  
                {  
                    wprintf(L"Error getting prefix, error is %08.8lx", hr);  
                    return -1;  
                }  
                if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))  
                {  
                    wprintf(L"Error getting local name, error is %08.8lx", hr);  
                    return -1;  
                }  
                if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))  
                {  
                    wprintf(L"Error getting value, error is %08.8lx", hr);  
                    return -1;  
                }  
                if (cwchPrefix > 0)  
                    wprintf(L"Attr: %s:%s=\"%s\" \n", pwszPrefix, pwszLocalName, pwszValue);  
                else  
                    wprintf(L"Attr: %s=\"%s\" \n", pwszLocalName, pwszValue);  
            }  
  
            if (S_OK != pReader->MoveToNextAttribute())  
                break;  
        }  
    }  
    return hr;  
}  

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlReader Methods