We help IT Professionals succeed at work.
Get Started

Reading data from XmlNode response from a SharePoint web service

vyotsukura asked
Last Modified: 2012-05-08
I am trying to read data from the response from the SharePoint Lists web service. My code is attached and it is pretty much straight from the MSDN library for returning list items using the SharePoint Lists web service. But when I loop through the XmlNode (nodeListItems) that presumably contains the data, on the second loop through, I get an XML stream in the innerXml string that appears to have everything that I need. What I cannot figure out from MSDN is how to properly read this data. There are 3 listItems in every one of these responses and only the second listItem has any useful data. Do I create an XmlNodeReader only on the second listItem? Am I on the right track?

I have read numerous online postings on reading XmlNodes, but I have not puzzled this one out.
string siteUrl = Properties.Settings.Default.SharePointSiteUrl;
                string libraryGUID = Properties.Settings.Default.LibraryGUID;

                SPListService.Lists spLists = new SPListService.Lists();
                spLists.Url = siteUrl + @"/_vti_bin/lists.asmx";

                spLists.Credentials = System.Net.CredentialCache.DefaultCredentials;

                // Instantiate an XmlDocument object
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

                string listName = libraryGUID;
                string viewName = "";
                string rowLimit = "500";

                /*Use the CreateElement method of the document object to create elements for the parameters that use XML.*/
                System.Xml.XmlNode query = xmlDoc.CreateElement("Query");

                System.Xml.XmlNode viewFields =

                System.Xml.XmlNode queryOptions =

                query.InnerXml = "<Where><And><Eq><FieldRef Name=\"CONTRACT_NO\"/><Value Type=\"Text\">" + contractNo + "</Value></Eq>" +
                    "<Eq><FieldRef Name=\"ACTIVITYTYPE\"/><Value Type=\"int\">" + activityType + "</Value></Eq></And></Where>";

                viewFields.InnerXml = "<FieldRef Name=\"CONTRACT_NO\" />" +
                    "<FieldRef Name=\"ACTIVITY\" />" +
                    "<FieldRef Name=\"ACTIVITYDATE\" />" +
                    "<FieldRef Name=\"DOCCATEGORY\" />" +
                    "<FieldRef Name=\"DOCSTATUS\" />" +
                    "<FieldRef Name=\"DOC_TYPE\" />" +
                    "<FieldRef Name=\"RECEIVED\" />" +
                    "<FieldRef Name=\"FIRSTVIEWDATE\" />" +
                    "<FieldRef Name=\"REFNO\" />"; 

                queryOptions.InnerXml = "";

                System.Xml.XmlNode nodeListItems = spLists.GetListItems
                    (listName, viewName, query, viewFields, rowLimit, queryOptions, null);

                foreach (System.Xml.XmlNode listItem in nodeListItems)
                    string innerXml = listItem.InnerXml;

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE