Partager via


MoveToNextAttribute

 

Advances the reader to the next attribute.

Syntax

  
HRESULT MoveToNextAttribute ();  

Return Value

Returns S_OK if no error is generated. Returns E_PENDING if the data is unavailable, and the stream is paused. Returns S_FALSE if there are no more attributes on this element.

Remarks

This method moves the reader through the list of attributes. Moving through attributes invalidates properties for the element, because the element properties are replaced with attribute properties. If the attribute is unavailable this method returns E_PENDING and the stream is paused. If there are no more attributes, this method returns S_FALSE and the reader does not move forward. If the reader is positioned on an element, this method moves the reader to the first attribute of the element.

After this method is called, the attributes collection on this element is still accessible. The application can then call other methods that move the reader within the attributes collection.

Example

The following example uses the MoveToNextAttribute method to process all of the attributes on an element.

// This code is excerpted from XmlLiteReader.cpp.  
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)  
    {  
        // This is a sample of how one might handle E_PENDING  
        if(PENDING(pReader->MoveToNextAttribute())){  
            wprintf(L"Error getting value, Pending, error is %08.8lx", hr);  
            while (hr = E_PENDING){  
                ::Sleep(1000);  
                hr = pReader->MoveToNextAttribute();  
            }  
        }  
        else{  
            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

Source: XmlLiteReader.cpp
IXmlReader Methods