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?
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With