Time and space complexity for SDA parsing using object deserialization and xml xpath
Intersytems documentation says not to hold entire SDA as object in In-memory.
Set object = ##class(User.NewClass1).%New()
s object.Property1="one"
s object.Property2="two"
s object.Property3="three"
s object.Property4="four"
Set w=##class(%XML.Writer).%New()
set w.Charset="UTF-8"
Set w.Indent=1
set status=w.OutputToString()
set status=w.StartDocument()
Set status=w.RootObject(object,"Vivek")
set status=w.EndDocument()
If $$$ISERR(status) Do $system.OBJ.DisplayError(status) Quit
set xmlstring = w.GetXMLString()
// Serialize XML to Object
Set obj = ##class(User.NewClass1).%New()
Set reader = ##class(%XML.Reader).%New()
Set status =reader.OpenString(xmlstring)
Do reader.CorrelateRoot("User.NewClass1")
Do reader.Next(.obj,.status)
Write "Property1 "_obj.Property1
Was there a question? Yes, of course, Cache' supports methods to serialize and deserialize XML enabled objects. However, those methods have to apply to all sorts of general XML structures, and as a result, are much less efficient than ones where we have a very known/constrained data model. One specific case involves embedded serial objects - serializing these to XML will cause them to be instantiated in memory even if null. In addition, SDA containers can be arbitrarily large - we have examples of 50-100mb size containers. Depending on your partition size, attempting to deserialize an entire container can cause a <STORE> error.