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

HRESULT MoveToFirstAttribute ();

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.

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 :

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
           wprintf(L"Error getting value, Pending, error is %08.8lx", hr);
           while (hr = E_PENDING){
               hr = pReader->MoveToFirstAttribute();
           wprintf(L"Error moving to first attribute, error is %08.8lx", hr);
            return -1;


Header: XmlLite.h

Library: XmlLite.lib

© 2015 Microsoft