【问题标题】:How to add xml file data into ArangoDb?如何将 xml 文件数据添加到 ArangoDb 中?
【发布时间】:2016-04-17 06:55:02
【问题描述】:
<InputParameters>
    <Textbox>
        <Text>ABCD</Text>
        <Text>EFGH</Text>
        <Text>HIJK</Text>
    </Textbox>
</InputParameters>

假设我必须将此 xml 文件数据添加到 arangodb。怎么可能做到这一点?

【问题讨论】:

    标签: java json xml arangodb


    【解决方案1】:

    有两种适当的解决方案。 一种是将整个 XML 放入文档的属性中。这可能不适合对 xml 的有效负载进行 AQL 查询。

    另一种可能的方法是使用jsonml 将您的xml 转换为结构化的json 文档,并将它们存储在using their java library。不过,我不知道这在像 SOAP 这样的复杂 XML 上的扩展性如何。

    然后,您可以创建 AQL 查询来处理该集合,并为源 XML 的属性创建 FILTER

    【讨论】:

    • 这意味着对于每个 xml 数据,我首先必须将其转换为 json 文档格式 n 然后将其推送到 arango... 是这样吗?
    • 在 jsonml 的情况下 - 正确。节点模块对 expat xml 解析器具有二进制依赖性,因此无法在 ArangoDB FOXX-Service 内工作
    • 也许我们周五找时间看看如何智能地将它包裹在 arangodb java 驱动程序周围。
    • 关于 arango 全文搜索的另一个问题......当我做 PUT
      localhost:8529//_api/simple/fulltext { "collection" : "Metadata", "attribute" : "metadata" , "query" : "defined" }
      我得到这个结果:{ "result": [], "hasMore": false, "count": 0, "error": false, "code": 201我不明白这里有什么问题......你能帮我吗?
    【解决方案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-driver git repository 中找到更多示例。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多