Condividi tramite


MoveToFirstAttribute

 

Moves the reader position to the first attribute within the current node.

Syntax

  
HRESULT MoveToFirstAttribute ();  

Return Value

Returns S_OK if no error is generated. Returns E_PENDING if the data is unavailable, and the stream is paused. If there are no attributes on the current node, returns S_FALSE and does not move the position of the reader.

Remarks

This method is most often used to return to the beginning of the attribute list. If the data is unavailable this method returns E_PENDING and the reader does not move forward.

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

The following code moves to the first attribute of an element by calling MoveToFirstAttribute:

HRESULT WriteAttributes(IXmlReader* pReader){  
   const WHCAR* 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->MoveToFirstAttribute())){  
           wprintf(L"Error getting value, Pending, error is %08.8lx", hr);  
           while (hr = E_PENDING){  
               ::Sleep(1000);  
               hr = pReader->MoveToFirstAttribute();  
           }  
       }  
       else  
          {  
           wprintf(L"Error moving to first attribute, error is %08.8lx", hr);  
            return -1;  
          }  
   }  
}  
  

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

MoveToNextAttribute
MoveToAttributeByName
IXmlReader Methods
IXmlReader Methods