2012-07-25 45 views
2

我通过web服务通过java查询sharepoint上的列表。 它能正常工作,当我想获得整个列表,但我想 只查询部分的列表。它可以通过一个CAML查询就像这样:Java Web服务到Sharepoint查询

<Query> 
<Where> 
    <Gt> 
     <FieldRef Name='ID' /> 
     <Value Type='Number'>10</Value> 
    </Gt> 
</Where> 
</Query> 

我不知道如何通过Java虽然通过这个.. 现在我这样做:

GetListItemsResponse.GetListItemsResult result = port.getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID); 

哪里查询对象简直是空(它提取整个列表)。

我读的地方可以这样进行:

GetListItems.Query query = new GetListItems.Query(); 
query.getContent().add(generateXmlNode(QueryStringHere)); 

但我没有generateXmlNode方法。

任何想法?

回答

0

尝试删除[query]根节点。查询节点将在运行时由sharepoint添加。这应该能解决你的问题。

+0

这可能是,但它的另一个问题则。我在寻求别的东西。查询作为对象传递给port.getLIstItems()方法。尽管我不确定它是哪个对象。我想简单地传递xml字符串,但这是不可能的。任何想法我必须做什么对象来传递查询getlistitems()? – PoeHaH 2012-07-26 07:47:51

0

试试这个:

private static Object generateXmlNode(String string) throws Exception { 
    DocumentBuilder docBuilder = null; 
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); 
    docBuilder = dbfac.newDocumentBuilder(); 
    Document rootDocument = docBuilder.newDocument(); 
    rootDocument.setTextContent(string); 
    return rootDocument.getDocumentElement(); 

} 
1

我回答这个问题了,可能有同样的问题,让这里的人,即使其2岁。

private static Object generateXmlNode(String string) throws Exception { 
    DocumentBuilder docBuilder = null; 
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); 
    docBuilder = dbfac.newDocumentBuilder(); 
    Document rootDocument = docBuilder.newDocument(); 
    rootDocument.setTextContent(string); 
    return rootDocument.getDocumentElement(); 

} 

参数String string在这种情况下是查询作为XML(CAML)。 它可以被加载,例如从属性:

this.query = new String(readAll(new File(this.getClass().getResource("/Query.xml").toURI()))); 
this.queryOptions = new String(readAll(new File(this.getClass().getResource("/QueryOptions.xml").toURI()))); 

和查询看起来是这样的:

<Query> 
    <Where> 
    <And> 
     <And> 
      <Contains> 
       <FieldRef Name="Editor" /> 
       <Value Type="Text">Chandler</Value> 
      </Contains> 
      <Contains> 
       <FieldRef Name="FileRef" /> 
       <Value Type="Text">AuditDeleteTesting</Value> 
      </Contains>  
     </And> 
     <Eq> 
      <FieldRef Name="Created_x0020_Date" /> 
      <Value Type="DateTime">2013-09-11</Value> 
     </Eq>    
    </And>  

    </Where> 
</Query> 

而且queryOption:

<QueryOptions> 
    <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns> 
    <ViewAttributes Scope="RecursiveAll"/> 
    <DateInUtc>TRUE</DateInUtc> 
</QueryOptions> 

我会建议使用SharePoint查询助手,如果你不与CAML共同查询: https://spcamlqueryhelper.codeplex.com/

我h操作它有帮助。

编辑:我忘了提来源:http://www.javaworld.com/article/2078906/enterprise-java/java-tip-consuming-sharepoint-web-services-with-a-java-client.html?null