3.6 Hollywood serialization

The Hollywood (de)serialization mode is a special mode that allows you to serialize arbitrary Hollywood tables. In contrast to the first two modes, Hollywood mode doesn't require the table to follow a certain layout. You can serialize any table to XML in this mode, just as you can with Hollywood's ReadTable() and WriteTable() functions. The table can even contain binary data or code like Hollywood functions.

The disadvantage is that when deserializing XML data back to a Hollywood table in this mode, the XML must follow a certain convention because Hollywood needs to know the type of the data stored inside XML elements. Thus, even though it will probably work in most cases, it's not possible to generally deserialize any arbitrary XML data using the Hollywood serializer. You can only safely deserialize XMLs that have been serialized using the Hollywood serializer before. Here is an example, consider this Hollywood table:

t = {1, 2, 3, 4, 5, test = "Hello", subtable = {x = 5, y = 6, z = "8"}}

When serializing this table to XML using the Hollywood serializer, it will look like this:

<?xml version="1.0" encoding="utf-8"?>
      <z type="string">8</z>

You can see that sequential table indices are stored in the form of <item.n> and that the <z> tag has an additional type attribute that tells the deserializer that the value is to be stored as a string in the Hollywood table instead of a number. All these things are special conventions of the Hollywood serializer which is why it can't be used to deserialize arbitrary XML documents. The <root> tag that is at the top level can be changed to a different tag through the xml.SetSerializeOptions() function.

Note that the Hollywood serializer mode also supports binary data. So in case the table contains Hollywood functions or strings that contain binary data, that data will be encoded as Base64 in the XML.

To deserialize an arbitrary Hollywood table to an XML document and then serialize it back to a Hollywood table, you could do the following:

StringToFile(SerializeTable(t, "xml"), "test.xml")
copy_of_t = DeserializeTable(FileToString("test.xml"), "xml")

Show TOC