【发布时间】:2016-04-17 06:55:02
【问题描述】:
<InputParameters>
<Textbox>
<Text>ABCD</Text>
<Text>EFGH</Text>
<Text>HIJK</Text>
</Textbox>
</InputParameters>
假设我必须将此 xml 文件数据添加到 arangodb。怎么可能做到这一点?
【问题讨论】:
<InputParameters>
<Textbox>
<Text>ABCD</Text>
<Text>EFGH</Text>
<Text>HIJK</Text>
</Textbox>
</InputParameters>
假设我必须将此 xml 文件数据添加到 arangodb。怎么可能做到这一点?
【问题讨论】:
有两种适当的解决方案。 一种是将整个 XML 放入文档的属性中。这可能不适合对 xml 的有效负载进行 AQL 查询。
另一种可能的方法是使用jsonml 将您的xml 转换为结构化的json 文档,并将它们存储在using their java library。不过,我不知道这在像 SOAP 这样的复杂 XML 上的扩展性如何。
然后,您可以创建 AQL 查询来处理该集合,并为源 XML 的属性创建 FILTER。
【讨论】:
从 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-driver git repository 中找到更多示例。
【讨论】: