2016-09-16 76 views
1

我在模式數據庫中使用了marklogic模式。 當我使用Java API針對數據庫中的模式插入文檔並在其無效時拋出錯誤時,是否有辦法進行嚴格驗證?使用java api在模式數據庫中驗證文檔xsd

任何關於如何通過解決方案的幫助非常感謝。

回答

2

Java API的答案與for the REST API相同。您可以安裝REST變換。它可以是這個簡單:

xquery version "1.0-ml"; 

module namespace trans = "http://marklogic.com/rest-api/transform/validate"; 

declare function trans:transform(
    $context as map:map, 
    $params as map:map, 
    $content as document-node() 
) as document-node() 
{ 
    let $validate := validate strict { $content } 
    return $content 
}; 

注:上傳與這名變換「驗證」,作爲變換名稱必須命名空間相匹配。

你也可以使用Javascript實現這個轉換。有關更多信息,請參閱REST Application Developer's Guide中的Writing Transformations

+0

以上聲明中的命名空間http://marklogic.com/rest-api/transform是什麼意思? – Vikram

+0

上述語句中名稱空間marklogic.com/rest-api/transform的意義是什麼? 我在模式數據庫中使用以下命名空間的XSD: http://vikram.com/transdata/customertypes 如何使用我加載到數據庫的轉換來驗證XML文檔?我正在將transform = validate傳遞給以下命令: curl -X PUT -T developertype.xml -H「Content-type:application/xml」--anyauth --user admin:admin「http:// localhost: 8061/LATEST/documents?uri =/transdata/developertype.xml&transform = validate – Vikram

+1

該命名空間是創建REST XQuery轉換的文檔化方式(請參閱我的答案中的文檔鏈接)用於調用轉換外觀的url好的,爲了排除你的轉換問題,檢查ErrorLog.txt並使用xdmp:log。你的XSD應該能夠有任何命名空間,關於使用XSD模式的更多信息,請看:http://docs.marklogic.com/guide/app-dev/loading_schemas –