Accessing Xml Nodes

Is it possible, maybe using renoise.http libs, to access xml nodes by name to achieve its value?

example :

some_obj.find("root/child-name/another-child") ?  

Renoise document API offers observable_list:find, i don’t know if you can use that to create the xpath wrapper that you need?

I’ve tried an xpath wrapper but I was unable to make it work.

Now I’m trying to use renoise.Document.create(“MyDoc”){ xml_table } but I get this error

*** Document.create: expected a string or number in document construction tables as keys, like { some_value = 1} or {‘foo’, ‘man’, ‘bla’}.
*** stack traceback:

  
here's the complete code  
  
 -- xml  
 local request = Request({  
 url=XML_URL_VERSION,  
 timeout=1000,   
 method=Request.GET,   
 --data={nid=meta.nid},  
 --save_file=true, -- write to harddisk  
 default_download_folder = false, -- keep in temp folder  
 success=function(d, text_status, xml_http_request)  
  
 local xml_doc = XmlParser:ParseXmlText(d);  
  
 -- the table is loaded correctly  
  
 local my_document = renoise.Document.create("MyDoc"){ xml_doc }   
  
 oprint(my_document );  
 end  
 --complete=complete,  
 --error=error,  
 --progress=progress  
 })   
  
  

the xml document is really simple

  
  
<versioninformation><br>
<latestversion>some value</latestversion><br>
<latestversionurl>some url</latestversionurl><br>
</versioninformation>  
  
  

Well tables should have predefined keys (or keynames), here is the example using the internal routines:

  
preset_table = {  
 "Scheme", "NoteMatrix","NoteProfile","Distance","DistanceMode",  
 "OctaveRotation","OctaveRepeat","Termination","TerminationMode",  
 "NoteRotation","NoteRepeat","ArpeggioPattern","CustomPattern",  
 "NoteColumns", "ChordMode","InstrumentPool","InstrumentRotation",  
 "InstrumentRepeat","VolumePool", "VolumeRotation", "VolumeRepeat"  
 }  
  
class "PresetTable" (renoise.Document.DocumentNode)  
 function PresetTable:__init()   
 renoise.Document.DocumentNode.__init(self)   
 self:add_property("PresetVersion", "2.00")  
 for x = 1,#preset_table do  
 self:add_property(preset_table[x], "00")  
 end  
 end  
  
local preset_table = PresetTable()  
  
  

I don’t know what XmlParser exactly submits as results, but i suspect it submits everything including the root node definitions and these are probably not necessary.

We thought the same thing, but also removing root it doesn’t work.

Maybe because rprint of the table passed in argument is

[Attributes] => table
[ChildNodes] => table
[Name] => latestversion
[Value] => some value

I think the only way is to make work xpath, but since I’m not so much interested loosing time in lua I’ll try to iterate the table in the properly way and query for each node name

Well, for me xml path still has quite a few dark corners, i usually pick wrappers that do the job for me in that case, but so far the internal procedures within Renoise do it fine, but when it gets to deeper nesting, you can try to inspect the class snippets supplied with the Renoise lua documentation (the scripts folder has a subfolder called snippets)

Your table could be loaded in this kind of way:

  
version_table = { "latestversion","latestversionurl" }  
  
class "versioninformation" (renoise.Document.DocumentNode)  
 function versioninformation:__init()   
 renoise.Document.DocumentNode.__init(self)   
 for x = 1,#version_table do  
 self:add_property(version_table[x], "00")  
 end  
 end  
  
local version_table = versioninformation()  
  
version_file = "myxml.xml"  
local ok,err = version_table:load_from(version_file)  
if ok then  
 print(version_table:property("latestversion").value)  
end  
  

Ok, now I’m almost able to make it work, but I need to assign xml text from a string - instead using load_from - because xml data is received from request.

Is it possible ?

The most simplified example from the Renoise.ScriptingTool.API.lua:

  
-- create a document my_options = renoise.Document.create("versioninformation") { latestversion = "2,0", latestversionurl = "http://www.mysite.com/latestversion.php" }  

You would somehow need to reparse the xml through your own splitter. Dac, you have some reg-ex filter tips that can be used here? This kind of voodoo seems appropriate for the case here, but i don’t want to burn my hands on this area.