2012-07-25 55 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