Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing XML document in AWS DynamoDB

My need is to store XML documents in the database and then be able to retrieve it based on certain field values.

AWS DynamoDB fits my needs as it is a document database that allows me to query based on a key/index values. From the tutorials and demos, I am able to store a JSON document, but not able to store the same thing in an XML format.

I was not able to find any resource regarding storing XML documents in NOSQL databases, DynamoDB or otherwise. How do I handle such a scenario?

like image 739
TechiRik Avatar asked Oct 06 '16 00:10

TechiRik


Video Answer


2 Answers

Since there is no native support for XML I would suggest you define or use an xml<->json translator in your application before contacting DynamoDB.

like image 101
Chen Harel Avatar answered Sep 19 '22 04:09

Chen Harel


Here is a code sample using C# Newtonsoft and the DynamoDB SDK DocumentModel to convert data from a DynamoDB table to and from XML.

private Document DocumentFromXmlElement(XmlElement ndRow)
{
    string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(ndRow, Newtonsoft.Json.Formatting.None, true);
    Document document = Document.FromJson(json);
    return document;
}

private XmlElement DocumentToXMLElement(Document document, string docName)
{
    string json = document.ToJson();
    XmlDocument xmlDoc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json.ToString(), docName);
    return xmlDoc.DocumentElement;
}
like image 20
Regan Avatar answered Sep 17 '22 04:09

Regan