Haseb Ansari
Haseb Ansari

Reputation: 607

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 ?

Upvotes: 1

Views: 893

Answers (2)

Achim Brandt
Achim Brandt

Reputation: 211

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.

Upvotes: 2

dothebart
dothebart

Reputation: 6067

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.

Upvotes: 2

Related Questions