title: Handling SharePoint UpdateListItems XML Response
body: <p>I'm inserting some items into a SharePoint 2007 list using the Lists web service. I'm trying to write some code to handle any errors reported in the response, but navigating the XML is not working as expected. I'm attempting to get a collection of Result elements, then check each Result's ErrorCode child element for an error code. When I try to get the ErrorCode of the second result, it appears to give me the first result's ErrorCode again even though I'm calling SelectSingleNode on the second Result element. What am I doing wrong? Here is my data and code (with most of the z:row attributes omitted to keep it short):</p>
  
  <p>SharePoint response:</p>
  
  <pre><code>- &lt;Results xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;
      - &lt;Result ID="1,New"&gt;
            &lt;ErrorCode&gt;0x00000000&lt;/ErrorCode&gt; 
            &lt;ID /&gt; 
            &lt;z:row ows_ContentTypeId="0x0100760B0FF12756D249834F5B18A46B1A31" ows_Title="Seas-a-1-1-Target1" ows_PointID="1" ows_X_x0020_Value="355.000000000000" ... xmlns:z="#RowsetSchema" /&gt; 
        &lt;/Result&gt;
      - &lt;Result ID="2,New"&gt;
            &lt;ErrorCode&gt;0x80020005&lt;/ErrorCode&gt; 
            &lt;ErrorText&gt;The operation failed because an unexpected error occurred. (Result Code: 0x80020005)&lt;/ErrorText&gt; 
        &lt;/Result&gt;
    &lt;/Results&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>System.Xml.XmlNode response = listService.UpdateListItems("SCs", batchElement);
  
  XmlNamespaceManager nsm = new XmlNamespaceManager(response.OwnerDocument.NameTable);
  nsm.AddNamespace("sp", response.NamespaceURI);
  
  XmlNodeList results = response.SelectNodes("//sp:Result", nsm);
  foreach (XmlNode result in results)
  {
      System.Diagnostics.Debug.WriteLine(result.OuterXml);
      XmlNode node = result.SelectSingleNode("//sp:ErrorCode", nsm);
      System.Diagnostics.Debug.WriteLine(node.OuterXml);
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&lt;Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;&lt;ErrorCode&gt;0x00000000&lt;/ErrorCode&gt;&lt;ID /&gt;&lt;z:row ows_ContentTypeId="0x0100760B0FFF2756D249834F5B18A46B1A31" ows_Title="Seas-a-1-1-Target1" ows_PointID="1" ows_X_x0020_Value="355.000000000000" ... xmlns:z="#RowsetSchema" /&gt;&lt;/Result&gt;
  &lt;ErrorCode xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;0x00000000&lt;/ErrorCode&gt;
  &lt;Result ID="2,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;&lt;ErrorCode&gt;0x80020005&lt;/ErrorCode&gt;&lt;ErrorText&gt;The operation failed because an unexpected error occurred. (Result Code: 0x80020005)&lt;/ErrorText&gt;&lt;/Result&gt;
  &lt;ErrorCode xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;0x00000000&lt;/ErrorCode&gt;
  </code></pre>