2016-01-12 33 views

回答

2

從版本2.7.1開始,aragodb-java-driver支持寫入(createDocumentRaw(...))和讀取(getDocumentRaw(...)) 原始字符串。

例子:

arangoDriver.createDocumentRaw("testCollection", "{\"test\":123}", 
    true, false); 

隨着JsonML可以將XML字符串轉換成JSON字符串,並將其存儲到ArangoDB:

// writing 
String xml = "<recipe name=\"bread\" prep_time=\"5 mins\"</recipe> "; 
JSONObject jsonObject = JSONML.toJSONObject(string); 
DocumentEntity<String> entity =  arangoDriver.createDocumentRaw(
     "testCollection", jsonObject.toString(), true, false); 
String documentHandle = entity.getDocumentHandle(); 

// reading 
String json = arangoDriver.getDocumentRaw(documentHandle, null, null); 
JSONObject jsonObject2 = new JSONObject(str); 
String xml2 = JSONML.toString(jsonObject2)); 

您可以找到arangodb-Java的應用程序更多的例子git repository

+0

我們在[ArangoDB Cookbook](https://docs.arangodb.com/cookbook/JavaDriverXmlData.html)中加入了詳細描述, – dothebart

2

有兩個適當的解決方案。 一種是將整個XML放入文檔的屬性中。這對於在xml的有效負載上執行AQL查詢可能會有所幫助。

另一種可能的方法是使用jsonml將您的xml轉換爲結構化的json文檔並將它們存儲在using their java library中。儘管如此,我不知道如何在複雜的XML上進行擴展。

然後,您可以創建AQL查詢以處理該集合,而FILTER可以創建源XML的屬性。

+0

這意味着對於每一個xml數據我首先必須將其轉換成json文檔格式n然後將它推入arango ...是這樣嗎? jsonml情況下的 –

+0

- 正確。節點模塊對expat xml解析器具有二進制依賴關係,因此不適用於[ArangoDB FOXX-Service](https://www.arangodb.com/foxx/) – dothebart

+0

也許我們會在週五找到時間看看如何智能地圍繞arangodb java驅動程序進行包裝。 – dothebart

相關問題