scottcable

I'm retrieving data from a Share Point server via the Lists web services GetList method but I'm having trouble using the returned data.

The data returned in the InnerXml of the XmlNode can't be converted to XML or a DataSet since it appears that there is more than 1 root element. This is what I'm getting (actual data has been replace by more generic terms but the schema is correct).

<rsBig Smileata ItemCount="40" xmlns:rs="urnTongue Tiedchemas-microsoft-com:rowset">
<z:row ows_DocIcon="doc" ows_LinkFilename="Name number.doc" ows_Document_x0020_Type="12;#Job Sheet" ows_Install_x0020_Date="2006-10-09 00:00:00" ows_Site_x0020_Name="148;#Name" ows_Job_x0020_Number="Number" ows_Job_x0020_User="6;#" ows_Last_x0020_Modified="298;#2006-10-10 10:02:18" ows_ID="298" ows_owshiddenversion="2" ows_FSObjType="298;#0" ows_FileLeafRef="298;#Name Number.doc" ows_Date_x0020_Received="2006-09-12 00:00:00" ows_Modified="2006-10-10 10:02:17" ows_FileRef="298;#Department/Site/Shared Documents/Name/Number/Name Number.doc" ows_Editor="203;#Firstname Lastname" xmlns:z="#RowsetSchema" />



... then another 39 of these z:rows


</rsBig Smileata>


If I try using a foreach loop on the nodes contained by the XmlNode returned by GetList - it only iterates through the loop twice - once for the rsBig Smileata entry and then once for the actual 40 rows of data. I was expecting it to go around 40 times - once for each row of data.


Can anyone explain what is going on here Am I missing setting some parameter that dictates how the data is returned


If I use the code below I can walk through the xml and and this case just add the data row details to a multiline textbox. I could use the childChildNode.Attributes to do something with the data but I was wondering if there wasn't a more "databound" type of solution.


Code Snippet

foreach (XmlNode childNode in node)
{
// txtLists.Text += childNode.OuterXml + "\n";
if (childNode.HasChildNodes)
{
foreach (XmlNode childChildNode in childNode)
{
if (childChildNode.NodeType == XmlNodeType.Element)
{
txtLists.Text += childChildNode.OuterXml + "\n";
}
}
}
}




Thanks
Scott



Re: SharePoint - Development and Programming Working with the data returned by the GetList web service.

Chase M

The data is always returned in this manner as far as I know (I don't think you're doing anything wrong to get it like this).

To ease navigation of it, and let you look at the pieces you want to, I usually load the response from the web service in an XmlDocument like this:

XmlDocument wsResponse = new XmlDocument();

wsResponse.Load(new XmlNodeReader(webService.GetList(...)));

You should be able to load the XmlNode response from any of the web services using this method.

Once you've got the response loaded into XmlDocument, you'll need to add the namespace(s) to navigate it:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(wsResponse.NameTable);

nsmgr.AddNamespace("z", "#RowsetSchema");

Now, if you want to iterate through all the rows, it's easy:

XmlNodeList rows = wsResponse.SelectNodes("//z:row", nsmgr);

foreach(XmlNode row in rows)

{

// do something

}

Hope that helps,

Chase






Re: SharePoint - Development and Programming Working with the data returned by the GetList web service.

scottcable

Thanks Chase - that works perfectly.

I can see now (and after your previous reply) that a deeper understanding of XML is required when working with the SP web services - both to request the data in the form of query that is built and to make sense of the return data. Thanks again.

Scott.





Re: SharePoint - Development and Programming Working with the data returned by the GetList web service.

MikeT1021

Chase M:

Thanks for that code snippet. It worked like a champ for me. I was doing it a totally different way, and yours is much more snazzy. It's amazing how many ways there are to skin a cat in .NET

You wouldn't happen to have similar code lying around to iterate through GetListAndView() results, would you ;-)

Mike

(no cats were actually skinned during the creation of my software)





Re: SharePoint - Development and Programming Working with the data returned by the GetList web service.

MikeT1021

I discovered a great website that describes how to use XPath for Sharepoint results simliar to the way Chase did, but on a grander scale.

http://www.csharphelp.com/archives4/archive602.html

There are a number of namespaces Sharepoint uses for its return values, #rowsetSchema being only one of them. This website shows you how to add _all_ the Sharepoint namespaces to your XmlDocument so that you can use XPath whenever and wherever you'd like, including for GetListAndView() results.

It's a happy day today!