1

有没有人使用 http:///_vti_bin/lists.asmx 服务中的 GetListItems() 方法成功地编写代码从 SharePoint 2007 列表(特别是 InfoPath 表单库)中提取数据(并且活着告诉它)?它返回了我一生中见过的一些最糟糕的 XML(它甚至不是兼容的 XML)。有没有一些简单的方法来解析 C# 中的数据,还是我需要手动解析它?

对此的任何帮助将不胜感激。

4

2 回答 2

2

当然,这不是最漂亮的做事方式,但它只是获得正确示例的问题。

我使用以下代码从获取列表查询中获取“东西”。

public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xmlToQuery.OuterXml);
    XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
    mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
    mg.AddNamespace("z", "#RowsetSchema");                                   
    mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
    mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
    mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
    mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");
    return doc.SelectNodes(xPathQuery, mg);
}

调用它使用

    XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());
    foreach (XmlNode listItem in SPCollection.XpathQuery(items, "//sp:listitems/rs:data/z:row"))
    {
        XmlAttribute id = listItem.Attributes["ows_Id"];
        if (id != null)
        {
            pageId = id.Value;                    
        }

    }

该示例并没有做很多事情,但希望它能让您了解如何获取数据。是的,我非常不喜欢 XPathQueries 的整个命名空间问题,但你会怎么做。

我只是对重写 SharePoint Web 服务不感兴趣,尤其是在我们的环境中进行测试和发布本身就需要花费数周的时间。但有时,别无选择。例如,如果您想访问 SPWeb 的自定义属性包或使用特定的站点模板和内容数据库(或任何其他未在 Web 服务中实现的数百万事物)创建 SiteCollection。但是,对于简单的列表访问,Web 服务似乎还不错。

于 2009-04-23T21:57:14.820 回答
1

InfoPath 无法处理来自 Lists Web 服务中的 GetListItems 的 XML。使用 InfoPath 2007,您有两种选择:

  1. 使用不允许过滤列表内容的 InfoPath 2007 SharePoint 数据连接。您必须将所有内容抓取回客户端(或服务器,如果它是 InfoPath Forms Services),然后在 InfoPath 规则中对其进行过滤。
  2. 编写一个驻留在 SharePoint 中的 Web 服务,它以 InfoPath 2007 可以消化的格式返回数据。我之前已经这样做了,您可以将列表名称和 CAML 查询以及一组字段传递给它,它将返回名称/值对的行。不幸的是,我目前不允许共享此代码。
于 2009-04-23T17:38:46.577 回答