2012-06-26 69 views
0

我使用ServiceClient對象(無客戶端代碼生成)從Java Axis 2客戶端調用SharePoint 2010 Web服務。Axis 2 Web服務上沒有AXIOMXPath的結果

我需要用xPath查詢結果以獲取結果代碼和其他數據在未來的發展。

使用AXIOMXPath我不能得到的結果...

這裏是Web服務調用的結果:

<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
    <CopyIntoItemsResult>0</CopyIntoItemsResult> 
    <Results> 
     <CopyResult ErrorCode="Success" DestinationUrl="http://mss2010-vm1/siteBdL/GED/obligations/obli_interne.pdf"> 
     </CopyResult> 
    </Results> 
</CopyIntoItemsResponse> 

我的代碼:

OMElement result = client.sendReceive(copyService); 

if (result != null) { 
    AXIOMXPath xpathExpression = new AXIOMXPath("/CopyIntoItemsResponse/Results/CopyResult/@ErrorCode"); 

    xpathExpression.addNamespace("", "http://schemas.microsoft.com/sharepoint/soap/"); 

    Object node = xpathExpression.selectNodes(result); 

    if (node != null) { 
     OMAttribute attribute = (OMAttribute) node; 

     if (attribute.getAttributeValue().equals("Success")) { 
     succeeded = true; 
     } 
    } 
} 

任何想法,請?

回答

0

我看到這裏可能會導致問題兩件事情:

  • 當編譯XPath表達式,你要綁定一個命名空間爲空前綴。這是Jaxen(這是Axiom使用的XPath實現)允許的,但它是不尋常的,不推薦。 XML規範,如XSLT,例如不要這樣做:在XSLT中,出現在XPath表達式中的非限定名稱總是被解釋爲沒有名稱空間的名稱,即使在作用域中有一個默認名稱空間。在你的情況下,XPath表達式的@ErrorCode部分可能有問題。預計會匹配沒有命名空間的ErrorCode屬性,但我認爲@ErrorCode實際上是指一個屬性,其本地名稱爲ErrorCode,命名空間爲http://schemas.microsoft.com/sharepoint/soap/(我不是100%確定的;我將不得不參考XPath規範)。
  • XPath表達式中的第一個/與包含上下文節點的樹的根節點(即,您傳遞給selectNodes的節點)匹配。對於sendReceive的結果,這可能是包含整個SOAP消息的文檔節點。爲避免此問題,請創建一個新的OMDocument,並將sendReceive的結果添加到該文檔或使用self::CopyIntoItemsResponse/...作爲XPath表達式。
+0

我回來一段時間後給出了一個反饋。我無法確認爲什麼AXIOMXPath不能正常工作。我選擇使用Axiom OMElement API來獲得結果(使用幾個getChildren()來「導航」到XML中)。如果我有時間,我會測試你的第二個主張...... – Dino