Export SharePoint Data as XML

I need help creating a script to pull specific data from a MS SharePoint list when requested via HTTP (Msxml2.ServerXMLHTTP).

I do not think I can use owssvr.dll directly, because the list contains sensitive information that I do NOT want to be accessible.  I would also like to add XML information such as the date of the request.

A web server will request the XML data from a remote server running SharePoint.  The web server will then filter and sort the XML records.

I have MS FrontPage 2003, if that makes it easier.

Thank you for your advice!
Who is Participating?
Sorry, I've been swamped, and then didn't go online over the weekend.

I'm mostly familiar with how to do this using Visual Studio, and it automatically generates the proxy code you'll need to interact with the web service.  I think you can use FrontPage for this...but I rarely use it, so I can't say for sure.  You can always write your code in Notepad, and compile it using CSC, of course.  But that's the hard way.  This Blog outlines a way to get List data from the SharePoint List service using FrontPage, but make sure that your data is security trimmed...as I said, I rarely use FrontPage, so I can't swear that this will meet your needs:


You can always construct a SOAP message manually in using MSXML's DomDocument object, then POST the message to the web service endpoint using Msxml2.ServerXMLHTTP (as you mentioned in your first post).  Or you can download the SOAP toolkit, and use the wsdl.exe to generate the proxy for you.  

Assuming you had a web reference (say, from Visual Studio, or from the proxy generated by the SOAP toolkit), this is how you'd get data from a list (in C#, from the WSS SDK):

Web_Reference_Folder_Name.Lists listService = new Web_Reference_Folder_Name.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

XmlDocument xmlDoc = new System.Xml.XmlDocument();

XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions","");

ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
ndViewFields.InnerXml = "<FieldRef Name='Field1' /><FieldRef Name='Field2'/>";
ndQuery.InnerXml = "<Where><And><Gt><FieldRef Name='Field1'/>" +
    "<Value Type='Number'>5000</Value></Gt><Gt><FieldRef Name='Field2'/>" +
    "<Value Type='DateTime'>2003-07-03T00:00:00</Value></Gt></And></Where>";
    XmlNode ndListItems = listService.GetListItems("List_Name", null, ndQuery,
        ndViewFields, null, ndQueryOptions);

catch (System.Web.Services.Protocols.SoapException ex)
    MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText +
         "\nStackTrace:\n" + ex.StackTrace);

Here are a few URLs to get you started:

The Windows SharePoint Services SDK has a lot of info to start:

    -    http://www.microsoft.com/downloads/details.aspx?familyid=1c64af62-c2e9-4ca3-a2a0-7d4319980011&displaylang=en

You can always browse directly to the SharePoint web service endpoint, and see what nice things it has to offer.  For example, on one of my dev servers where I have SharePoint running, I can go to this URL:

    -    http://dev01wpssearch/_vti_bin/lists.asmx

This shows me all operations on lists that SharePoint supports via this web service.  In particular, you'd be interested in the GetListItems() method:

    -    http://dev01wpssearch/_vti_bin/lists.asmx?op=GetListItems

The SOAP message looks like:

POST /_vti_bin/lists.asmx HTTP/1.1
Host: dev01wpssearch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetListItems"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">

Here's the SDK info for the GetListItems method.  As you can see, you can specify a ViewName

GetListItems Method

The GetListItems method of the Lists service returns information about items in the list based on the specified query.


listName   A string that contains either the title or the GUID for the list. When querying the UserInfo table, the string contains "UserInfo".

viewName   A string that contains the GUID for the view, which determines the view to use for the default view attributes represented by the query, viewFields, and rowLimit parameters. If this argument is not supplied, the default view is assumed. If it is supplied, the value of the query, viewFields, or rowLimit parameter overrides the equivalent setting within the view. For example, if the view specified by the viewFields parameter has a row limit of 100 rows but the rowLimit parameter contains 1000, then 1,000 rows will be returned in the response.

query   A Query element containing the query that determines which records are returned and in what order and that can be assigned to a System.Xml.XmlNode object, as in the following example:

         <FieldRef Name="ID" />
         <Value Type="Counter">3</Value>
If supplied, the value of this parameter overrides either the query within the view specified by the viewName parameter or the query within the default view for the list.

viewFields   A ViewFields element that specifies which fields to return in the query and in what order, and that can be assigned to a System.Xml.XmlNode object, as in the following example:

   <FieldRef Name="ID" />
   <FieldRef Name="Title" />
If supplied, the value of this parameter overrides the view fields within the view specified by the viewName parameter or the view fields in the default view for the list.

rowLimit   A string that specifies the number of items, or rows, to display on a page before paging begins. If supplied, the value of this parameter overrides the row limit set in the view specified by the viewName parameter or the row limit set in the default view for the list.

queryOptions   An XML fragment in the following form that contains separate nodes for the various properties of the SPQuery object and that can be assigned to a System.Xml.XmlNode object:


This article shows how to get the list from SharePoint, and convert it into a DataSet.  This might be convenient if you need to end up with a DataSet for some reason.

    -    http://www.developer.com/tech/article.php/3104621

Mike Sharp
You have number of possibilities, with SharePoint.  Since the current version of SharePoint doesn't do any security trimming (though SharePoint 2007 does), your best bet is to use the SharePoint web service for this.  I'm at home at the moment, but when I get to work, I'll post more info.

I use SharePoint web services quite a bit--they're very handy, and pretty easy to use.  You could use the Search service, which allows you to select the data from the list that you want, but there is a list service as well.  If I recall correctly, you can do almost anything you want via the web service, except create a new list...

In any case, I'll post an example when I get to work in a few hours.  Do you also have Visual Studio 2003, and is the client server (the one you're say you're going to use MSXML with) running ASP.NET?

Mike Sharp
llessurtAuthor Commented:
Please illustrate how to implement the SharePoint web service.

The client server is running ASP.NET -- I'm planning to save the XML response as a file so it can be accessed directly from the client.  The advice a need is how to compile the XML from the SharePoint list to send to the client.

I do not have Visual Studio.

Thank You
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

llessurtAuthor Commented:
Is there a better category to make this post?
llessurtAuthor Commented:
Thanks rdcpro, I'm still looking at your solution -- this process may not be as straightforward as I was hoping.  I am lacking in experience I guess.

FrontPage gives me a data connection very easily, but wants to format it in a table with with menus and so many on a page, etc.

Basically I want to open a SharePoint list, specify a query and the fields I want, add a the current date, and send the whole thing to the remote web server as an XML document.  The web server will save the document and access the saved version locally.

It will be accessible remotely, so it is important that only the specified fields with the query can be accessed (exported).

Am I going about this the wrong way?  With these methods, it looks like I will have to manually build the XML document (and I haven't been successful).
I wish I was more experienced with FrontPage.  No, wait, I take that back.  ;^)

Actually, it may not be possible at all, if FrontPage doesn't allow you to write any code.  But the DataSet doesn't have to be bound to a datagrid for display, and you should be able to get the XML directly from the DataSet.

Otherwise, you'll have to use the Web Service directly, and construct the web client yourself, assuming you can do this in FrontPage.  

You can always do this in code and compile from the command line, too.  Visual Studio is nice, but it's a luxury, not a requirement.  But I'd say development in Notepad and command line compilation is not for the faint of heart!

Mike Sharp
llessurtAuthor Commented:
I appreciate all your help.  I would repost, but I'm not sure where this question should go.  I downloaded Visual Studio Express 2005, but I have no idea what to do with it.

I'm looking for something very simple....  I know this is a mess, but it illustrates what I am looking for.

<%@ Page Language="VB" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
      Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities"
      Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.Sharepoint" %>

<script runat="server">

    Public Class SPWeb
        Inherits System.Object
    End Class
    Sub Page_Load()

        Dim mySite As SPWeb = SPControl.GetContextWeb(Context)
        Dim list As SPList = mySite.Lists("ATS Job Orders")

        Dim query As New SPQuery()
            query.Query = "<Where><Eq><FieldRef Name="Status"/><Value Type="x:string">In Print</Value></Eq></Where><OrderBy><OrderField Name="Created" Type="xsd:string" Direction="DESC"/><OrderField Name="Order_x0020__x0023_" Type="xsd:string" Direction="DESC"/></OrderBy>"

        Dim myItems As SPListItemCollection = list.GetItems(query)
        Dim item As SPListItem
        For Each item In myItems
            Response.Write("<book ID" & CHR(34) item("id").ToString() & CHR(34) & "><title>" & item("Title").ToString() & "</title></book>")
        Next item
        Dim list As SPList = mySite.Lists("Staff")
        Dim query As New SPQuery()
query.Query = "<Where><Eq><FieldRef Name="Status"/><Value Type="x:string">Open</Value></Eq></Where><OrderBy><OrderField Name="Created" Type="xsd:string" Direction="DESC"/><OrderField Name="Order_x0020__x0023_" Type="xsd:string" Direction="DESC"/></OrderBy>"

        Dim myItems As SPListItemCollection = list.GetItems(query)
        Dim item As SPListItem
         For Each item In myItems
            Response.Write("<name>" & item("Name").ToString() & "</name>")
        Next item
    End Sub

This ASP page retreives the data:

Option Explicit
On Error Resume Next
Response.Buffer = True

Dim xml, fso, xmldom, objNodeList

Set xml = Server.CreateObject("Msxml2.ServerXMLHTTP")
xml.Open "POST", "https://www.remoteserver.com/customexport.aspx", False

      Set fso = Server.CreateObject("scripting.FileSystemObject")
      Set datafile = fso.CreateTextFile("c:\booksauthors.xml", true)
      datafile.write xml.responseText
      Set datafile = Nothing
      Set fso = Nothing

Set xml = Nothing

response.redirect newpage
llessurtAuthor Commented:
I never did get SharePoint WebService to do what I wanted it to do.  I ended up using a table generated by MS-FrontPage (very easy to create with a few clicks), requesting it via HTTP (Msxml2.ServerXMLHTTP, and manipulating it as text to pull out the data and create an XML file.

I very much appreciate your help and suggestions.

Thank You!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.