tma Posted April 23, 2008 Share Posted April 23, 2008 I've writing code to save data arrays into XML which can be done fine with the current API e.g. function tuTableToXML(tbl,nodeName,node) for key,value in pairs(tbl) do if type(value) == "table" then tuTableToXML(value,key,xmlCreateSubNode(node,key)) else xmlNodeSetAttribute(xmlCreateSubNode(node,nodeName),key,value) end end end function tuTableToXMLFile(tbl,rootNodeName,fsp) local xf = xmlCreateFile(fsp,rootNodeName) tuTableToXML(tbl,rootNodeName,xf) return xmlSaveFile(xf) end This will traverse any array and save the contents to an XML file like: > > > id="580" /> upgrade="1101" /> > > id="479" /> > > dead="43" /> sb="0" /> vc="0" /> > The problem I've got now is that I want to be able to read this back into the array. I've looked at the API and the commands aren't there to do it - there's nothing to arbitrarily read back XML data. I check out _arc's racemap conversion source and noticed that to do this with a race map, he passes the structure of the file to his decoding routine. I'm looking for something wherein I can just read any XML without knowing the structure, into an array. In DP3, xmlNodeGetChildren() will allow the fetching of all the child nodes, but it doesn't solve the problem entirely. Would it be possible to add the following two functions ? xmlNodeGetTag(node): Returns the tag of the given node e.g. "stat", "vfav", "sillycar" etc. in the above example. I've tried xmlNodeGetValue() but this never seems to return anything (I assume value ~= tag ?) xmlNodeGetAttributes(node): Returns a list of the attributes for a given node. Eg. for something like : id="479" color="1,1" upgrades="1110" /> it would return an array like {"id","colour","upgrades"} Any chance of these additions ? Link to comment
norby89 Posted April 23, 2008 Share Posted April 23, 2008 yes, both have been requested Link to comment
Recommended Posts