Problem With Document Api And :Load_From()

So it seems the file loading mechanism only grabs a single level when loading a file? Was this intended?

Saving the following:

Click to view contents <?xml version="1.0" encoding="UTF-8"?>

<mixer_snapshots doc_version=“0”>

3



Snapshot 08/05/10 H03 M01 S43 PM



<snapshot_34253ada>

<track_count>10</track_count>

<track_1>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_1>

<track_2>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_2>

<track_3>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_3>

<track_4>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_4>

<track_5>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_5>

<track_6>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_6>

<track_7>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_7>

<track_8>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_8>

<track_9>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Analog Out 1/2 L Delta-66 & Analog Out 1/2 R Delta-66</output_routing>

</track_9>

<track_10>



<post_item>0.5</post_item>

<post_item>1.0</post_item>





<pre_item>0.5</pre_item>

<pre_item>1.0</pre_item>

<pre_item>0.0</pre_item>




1.0

false

<output_delay>0.0</output_delay>

<output_routing>Master Track</output_routing>

</track_10>

</snapshot_34253ada>

</mixer_snapshots>

Loads only this tiny part:

<?xml version="1.0" encoding="UTF-8"?>

<mixer_snapshots doc_version=“0”>
3
</mixer_snapshots>

Am i missing something how to use it correctly or is it a bug?

When loading something, make sure the root nodes are present in the document. New nodes will not be created automatically, except for lists.

In your case the doc must have the “track_X” nodes before you are loading it, in order to resolve them. A document list would solve this problem as well, but we right now don’t have one.

load_from()
– load the document tree from a XML file. This will not create new properties,
– except for list items, but will only assign existing properties in the
– document node with existing properties from the XML file.
– this means: nodes that exist in the XML only, will be silently ignored.
– nodes that exist in the document only, will not be altered in any way

Hmm, the root nodes would be probably <snapshot_34253ada> which contains the tracks. The problem is, that i don’t know the name of <snapshot_34253ada> until i have the names list, which didn’t load as well though. The name is basically “snapshot_ … crc32(snapshot name)” The names string list at the beginning isn’t loaded at least which should if loading creates nodes for lists?

Snapshot 08/05/10 H03 M01 S43 PM

I’ve noticed that numbers use <blah_item> in their lists but the names list defaulted to . Kinda confusing. Will fiddle more with it.

Ok, this is kinda insane. Now i have it loaded after having called :load_from() 4 times! Also i do end up with more tags than my original file had which is a problem, since i am checking for the presence of certain tags to decide if that/these value(s) can be restored or not. Now it seems like i have to store additional info into a snapshot what exactly can be loaded and what not, which was a simple check for a tag before. Is there a way to get the exact original content back? Maybe i’m still not using it right?

Here is my original saved file:

[luabox]

<?xml version="1.0" encoding="UTF-8"?>

<mixer_snapshots doc_version=“0”>
1.0

Snapshot 08/05/10 H06 M46 S11 PM

<snapshot_99465224>
<track_count>4</track_count>
<track_1>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false
<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_1>
<track_2>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false
<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_2>
<track_3>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false
<output_delay>0.0</output_delay>
<output_routing>Analog Out 1/2 L Delta-66 & Analog Out 1/2 R Delta-66</output_routing>
</track_3>
<track_4>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false
<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_4>
</snapshot_99465224>
</mixer_snapshots>
[/luabox]

The file after loading:

[luabox]

<?xml version="1.0" encoding="UTF-8"?>

<mixer_snapshots doc_version=“0”>
1.0

Snapshot 08/05/10 H06 M46 S11 PM

<snapshot_99465224>
<track_count>4</track_count>
<track_1>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false

<device_count>0.0</device_count>

<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_1>
<track_2>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false

<device_count>0.0</device_count>

<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_2>
<track_3>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false

<device_count>0.0</device_count>

<output_delay>0.0</output_delay>
<output_routing>Analog Out 1/2 L Delta-66 & Analog Out 1/2 R Delta-66</output_routing>
</track_3>
<track_4>

<post_item>0.5</post_item>
<post_item>1.0</post_item>

  
 0.5  
 1.0  
 0.0  
 

1.0
false

<device_count>0.0</device_count>

<output_delay>0.0</output_delay>
<output_routing>Master Track</output_routing>
</track_4>
</snapshot_99465224>
</mixer_snapshots>
[/luabox]

My loading function:

[luabox]
function snapshot_load_file()

if snapshots_filename == nil or snapshots_filename:len() == 0 or
not snapshots_filename:find(".snapshots$") then

return
end

ra:show_status("Loading: " … snapshots_filename)

if io.exists(snapshots_filename) then

local snapshot_name = nil
local snapshot_node = nil

– create and get the list of snapshot names
snapshots:add(“names”, {""})
snapshots:load_from(“mixer_snapshots”, snapshots_filename)

– create and get the names of the snapshot tags and the track count
for s = 1, #snapshots.names do
snapshot_name = “snapshot_” … crc32(snapshots.names[s].value)
snapshot_node = snapshots:add(snapshot_name, rd.create {track_count = 0})
end
snapshots:load_from(“mixer_snapshots”, snapshots_filename)

– create and get any track specific settings
for s = 1, #snapshots.names do
snapshot_name = “snapshot_” … crc32(snapshots.names[s].value)
snapshot_node = snapshots:property(snapshot_name)

for t = 1, snapshot_node.track_count.value do
local track_node = snapshot_node:add(“track_” … t, rd.create())

track_node:add(“post”, {0})
track_node:add(“pre”, {0})
track_node:add(“mute”, 0)
track_node:add(“solo”, false)
track_node:add(“devices”, rd.create {device_count = 0})
track_node:add(“output_delay”, 0)
track_node:add(“output_routing”, “”)
end
end
snapshots:load_from(“mixer_snapshots”, snapshots_filename)

– create and get any device specific settings
for s = 1, #snapshots.names do
snapshot_name = “snapshot_” … crc32(snapshots.names[s].value)
snapshot_node = snapshots:property(snapshot_name)

for t = 1, snapshot_node.track_count.value do
local track_node = snapshot_node:property(“track_” … t)

if track_node.devices.device_count.value > 0 then
for d = 1, track_node.devices.device_count.value do
local device_node = track_node.devices:add(“device_” … d, rd.create())

device_node:add(“active_preset”, 0)
device_node:add(“parameters”, {0})
end
end
end
end
snapshots:load_from(“mixer_snapshots”, snapshots_filename)

end

snapshots:save_as(“mixer_snapshots”, rt.bundle_path … “debug.snapshot”)

end
[/luabox]

Before scratching a hole into your head: could you send me the complete tool or attach it here, so that I can have a look at this?

I’ve sent you a mail with my current version attached.

Have you guys figured out a way to do this? Do you have to serialize/deserialize everything via lists before you can load/save dynamically created data from XML? I think having the document structure mirror the XML structure automatically would be great, but are there safety concerns with this or is it just hard to make it work like that?