Thanks for the replies.
Yeah that clarifies things I already know.
Feeling a bit better now after going to sleep unsatisfied after a very confusing day.
i.e. doughting my intellegence yet again. (happens more often that I'd like)
As a beginner I would prefer to have actual working samples.
I can make reasonable deductions myself then when nothing seems to work I ask.
Working with a datagrid and an array - NOT from XML
I'd like to load the grid with my array using field names from item x as column headers or OK keyNames.
Then later, when I want to play with the column properties I'll research how to do it.
Or later when I know how to use the datagrid properly
I can then load the columnheading properties then the griddata.
Like hiding my data by making a certain columnWidth 0 etc.
I've kinda given up on the XML to datagrid.
Or come to the realizatoin that MY XML tree data doesn't really fit in with a datagrid solution
To much complexity and no actual working example was a hard learn.
with my XML tree data - a large amount does NOT repeat so having heading at all doesn't work.
Which wouldn't work with a dataGrid
Then the next part DOES have monthly data and then daily data that I need to stay in the month/day order given in the XML tree data.
Which should work well with a dataGrid.
If anyone at all has a working example no matter how small or simple could you please post it?
I'm trying to use the XML to Array but the array comes out out of XML order.
i.e. I don't need it to sort the array.
I need the array in the exact order the XML was presented.
Also, that script working with the keys has nothing to work with and returns nothing.
So It's just theArray that I'm working with at the mo.
Code: Select all
-- I have no control over my data
-- some days it works without mods
-- other days it contains special characters and throws LiveCode XML routines off.
-- put field "txtField" into theXML
local tPreferencesData, tResult
put url ("file:" & "c:/myXML.xml") into tXMLData
put the result into tResult
if tResult is not empty then
answer error "Failed to read XML Data file at location: " & "c:/myXML.xml"
-- Remove non-breaking spaces -
replace " " with empty in tXMLData
-- Remove Delay tagged lines - always corrupted
Put wordOffset("<delay",tXMLData) into tWordStartNum
Put wordOffset("delay>",tXMLData) into tWordEndNum
Delete word tWordStartNum to tWordEndNum of tXMLData
--filter tXMLData without "*<delay*</delay>" -- this works as well - thanks dglass
put tXMLData into theXML
replace cr with empty in theXML
-- Convert xml to array. Store data in array as UTF8.
put ConvertXMLToArray(theXML, "UTF-8") into theArray -- handler in RevOnline stack
-- Convert to an array that can be assigned to the dgData of a Data Grid (numerically indexed).
-- put SortArrayKeysWithXMLOrdering(theArray["myxml"]) into theKeys -- handler in RevOnline stack
-- put 0 into i
-- repeat for each line theKey in theKeys
-- add 1 to i
-- put theArray["myxml"][theKey] into theData[i]
-- end repeat
put displayArrayData2 (theArray, "") into x
replace " => Array" with empty in x
put x into field txtField2 - much better formatting than the dataGrid in the exact example
--combine theArray using return and tab
-- put theArray into field "Table Field"
-- put theArray into field txtField2
-- --put theArray into field DataGrid 1
-- set the dgData of group "DataGrid 1" to theData
-- lock screen
-- This works setting up the column headings with Return as the delimiter
-- put "Col1" & return & "Col21" & return & "Col3" into tColumnTitles
-- set the dgProp["columns"] of group "DataGrid 3" to tColumnTitles
-- NOTE: the GridData array Keys MUST match the colounHeading Names.
-- ??? lost here with this exact XML implementation - may work better NOT using XML
-- set the dgData of group "DataGrid" to theData --[??? entries]
-- unlock screen
-- NOTE: there is also a gdText property you can use
function displayArrayData2 pArray, pIndent
# create the variable that loops through the keys in the array
if pArray is an array then
# print information to indicate that we are entering a new nested level of the array
get "Array" & return
# print full stops that allow the reader to track the depth of an element
--put "." after pIndent
# create the indentation
put tab after pIndent
repeat for each key tKey in pArray
# call displayArrayData with a nested array
--put format("%s[%s] => %s\n", pIndent, tKey, displayArrayData2 (pArray[tKey], pIndent)) after it
put format("%s%s => %s\n", pIndent, tKey, displayArrayData2 (pArray[tKey], pIndent)) after it
delete the last char of it