简体   繁体   中英

How to add xml file data into ArangoDb?

<InputParameters>
    <Textbox>
        <Text>ABCD</Text>
        <Text>EFGH</Text>
        <Text>HIJK</Text>
    </Textbox>
</InputParameters>

Suppose i have to add this xml file data into arangodb. How would one able to do so ?

There are two proper solutions. One is to put the whole XML into an attribute of a document. This will then in term probably be not good for doing AQL queries on the payload of the xml.

Another possible approach could be to use jsonml to translate your xml into structured json documents, and store them using their java library . I don't know how well this scales on complex XML like SOAP though.

You could then create AQL queries to work on that collection and FILTER for attributes of the source XML.

Since version 2.7.1 the aragodb-java-driver supports writing (createDocumentRaw(...)) and reading (getDocumentRaw(...)) of raw strings.

Example:

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

With JsonML you can convert a XML string into a JSON string and store it into 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));

You can find more examples in the arangodb-java-driver git repository .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM