将数据从sharepoint获取到drupal

时间:2010-03-16 15:58:26

标签: web-services sharepoint drupal

问题:
我即将为一家公司开发一个Drupal站点,该公司在sharepoint环境中存储大量数据(产品,食谱等......)。我需要以某种方式将这些信息输入我的Drupal系统。最好将其保存为drupal节点 该信息也将在sharepoint系统中编辑/添加,因此除了将数据保存到drupal之外,它还必须定期检查更新。

解决方案的一个想法是使用某种Web服务来检索数据,但我不知道如何在drupal中完成。

所以我的问题是:有没有人做过这样的事情,如果有的话,或者有人对如何做到这一点有任何建议吗?

任何答案都将受到高度赞赏。

/安德斯

5 个答案:

答案 0 :(得分:3)

我强烈建议您仔细查看FeedAPI module and it's extensions

我成功地使用了它:

  • '开箱即用'用于从RSS源创建节点
  • 稍微修改了从Webservice的内容创建节点
  • 作为自定义模块实现的蓝图/示例,该实现从另一个Web服务的内容创建节点(那里有一些非常特殊的需求,需要自定义解决方案)

听起来,如果您对sharepoint数据的公开方式有一定的控制权,那么您应该能够成功使用FeedAPI而不需要任何修改,但也许您需要实现自己的解析器扩展(再次,检查已经编写的附加模块以扩展FeedAPI以获取示例,如果不是解决方案)。

答案 1 :(得分:2)

我们已经在我们设置的许多Web服务上完成了这项工作,并且很快也将为Sharepoint执行此操作。如您所说,您可以使用XML获取数据。所以你只需要 1)检索XML数据 2)解析XML数据 3)在Drupal

中的块中返回现在可读的数据

对于1,您需要打开任何防火墙访问并提供可公开读取的XML源,或者只能通过Drupal服务器的IP或其他一些身份验证机制来设置它。 对于2PHP,您可以获得有关如何解析XML的许多选项。我们创建了一个模块来处理XML服务,然后我们从处理显示,主题等的另一个模块调用它。下面我将首先提供XML模块中两个函数的示例,然后是一个如何使用的示例可能会在另一个模块中使用它。

这是来自XML模块。

/**
 * Retrieving XML data from the URL
 * 
 * @param $url
 *    The url to retrieve the data
 * @param $replace_special_characters
 *   Replace special character to HTML format
 *   
 * @return parse result as struct 
 */
function xmlservice_parse($url, $replace_special_characters = FALSE) {
    $http_contents = drupal_http_request($url);
    if (!isset($http_contents->data)) {
        throw new RuntimeException("Cannot get contents from the URL");
    }//if

    if($replace_special_characters)
        $http_contents_data = str_replace('&','&', $http_contents->data);
    else
        $http_contents_data = $http_contents->data;

    $xml_parser = xml_parser_create();
    xml_parse_into_struct($xml_parser, $http_contents_data, $result);
    xml_parser_free($xml_parser);

    return $result;
}

/**
 * Retrieving XML data as Dom document from the URL
 * 
 * @param $url
 *    The url to retrieve the data
 * @param $replace_special_characters
 *   Replace special character to HTML format
 * 
 * @return result as Dom Document
 */
function xmlservice_parse_to_dom($url, $replace_special_characters = FALSE) {
    $http_contents = drupal_http_request($url);
    if (isset($http_contents->error)) {
        throw new RuntimeException($http_contents->error);
    }//if
    if (!isset($http_contents->data)) {
        throw new RuntimeException("Cannot get contents from the URL");
    }//if

    if($replace_special_characters){
        $http_contents_data = str_replace('&','&', $http_contents->data);
    }//if
    else{
        $http_contents_data = $http_contents->data;
    }//else

    $dom_document = new DomDocument;
    /* load htmlinto object */
    $dom_document->loadXML($http_contents_data);
    /* discard white space */
    $dom_document->preserveWhiteSpace = false;

    return $dom_document;
}

然后只需编写代码即可创建一个块。如果您不知道如何操作,请查看创建简单块的http://www.nowarninglabel.com/home/creating-a-new-custom-module-in-drupal-6。然后,对于内容,您可以在XML文档上调用上述函数之一,例如$ content = xml_service_parse('http://sharepoint.example.com/some/thing/feed.xml');

如果要解析节点,可以只使用XML函数,而是使用node_save()以编程方式创建节点:http://api.drupal.org/api/function/node_save 我还没有太多关注可用的Sharepoint服务,但您可能只是将XML解析为如上所示的dom文档,然后通过它循环创建一个符合您标准的每个XML节点的节点。

如果你想为

做更多的工作

希望这很有帮助。随意询问更多细节。

答案 2 :(得分:0)

Sharepoint将数据保存在MS SQL数据库中,对吗?我的一位同事写了a good outline of the process we used in moving data from MS SQL to Drupal

答案 3 :(得分:0)

你绝对可以通过网络服务与它交谈。我们之前已将Drupal站点连接到MS Great Plains。

答案 4 :(得分:0)

默认情况下,SharePoint会公开Web服务。如果您可以访问SharePoint网站中的项目,则还应该能够使用Web服务访问它们。请记住,从代码访问Web服务时,请传递正确的用户凭据。

如果你只需要在Drupal中使用readaccess,你也可以使用rss feed。使用rss feed来过滤,排序或查找特定项目可能会有点困难。

不建议直接从数据库中读取,因为Microsoft不保证数据模式在软件更新之间保持不变。