从 SharePoint Web 服务查询列表数据

发布于 2024-07-17 13:32:14 字数 244 浏览 5 评论 0原文

是否有人曾使用 http:///_vti_bin/lists.asmx 服务中的 GetListItems() 方法成功编写代码以从 SharePoint 2007 列表(特别是 InfoPath 表单库)中提取数据(并且有幸讲述了这一点)? 它返回了我一生中见过的一些最差 XML(它甚至不是兼容的 XML)。 是否有一些简单的方法来解析 C# 中的数据,或者我是否需要手动解析它?

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

Has anybody ever successfully written code to extract data from a SharePoint 2007 list (specifically, an InfoPath form library) using the GetListItems() method in the http:///_vti_bin/lists.asmx service (and lived to tell about it)? It returns some of the worst XML I've seen in my life (it's not even compliant XML). Is there some easy way to parse the data in C# or am I going to need to parse through it manually?

Any help on this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海似她心 2024-07-24 13:32:14

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

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

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。 然而,对于简单的列表访问,网络服务似乎很好。

Sure it is not the prettiest way of doing things, but it simply a matter of getting the correct examples.

I have used the following code to get "stuff" out of a get lists query.

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);
}

Calling it using

    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;                    
        }

    }

The example does not do a whole lot, but hopefully it gives you an idea of how to go about getting the data out.
Yes I intensly dislike the whole namespace issue with XPathQueries, but what are you gonna do.

I am just not that interested in re-writing the SharePoint web services, especially as testing and releasing in our environment is weeks worth of effort in and of itself. Sometimes though, there is no option. E.g. if you want to access the custom property bag of an SPWeb or create a SiteCollection using a specific Site Template and content database (or any of the other million things that are not implemented in the web services). However, for simple list access, the webservices seem fine.

萧瑟寒风 2024-07-24 13:32:14

InfoPath 无法处理列表 Web 服务中的 GetListItems 中的 XML。 对于 InfoPath 2007,您有两个选择:

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

InfoPath cannot handle the XML from GetListItems within the Lists web service. With InfoPath 2007 you have two options:

  1. Use the InfoPath 2007 SharePoint data connection which does not allow for filtering of list content. You have to grab all content back to the client (or server if it is InfoPath Forms Services) and then filter it within your InfoPath rules.
  2. Write a web service that lives within SharePoint that returns data in a format that InfoPath 2007 can digest. I have done this before where you can pass it a list name and CAML query and set of fields and it will return rows of name/value pairs. Unfortunately, I am not allowed to share this code at this time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文