

- #Nested grid start open scriptcase code
- #Nested grid start open scriptcase series
- #Nested grid start open scriptcase free
# The function revXMLAttribute allows us to read attributes from XML files, # its exactly the same as revXMLNodeContents, # except that you also need to tell it which attribute you want. We extract the contents and the # attribute in two separate calls. # Extract the introductory message preference. Put revXMLNodeContents(pTree, "preferences/textSize") into tTextSize Put revXMLNodeContents(pTree, "preferences/textColor") into tTextColor # These are simple nodes in the XML file, # we can get what is inside them using the revXMLNodeContents function # This function will return a string beginning with "xmlerr," # if it fails, but we don't check this # here as we created the file and we know it won't fail. # Extract the text color and text size preferences. private command processPreferencesTree pTree
#Nested grid start open scriptcase series
We use a series of calls to the XML library to extract each piece of information from the tree. Once we have the XML tree, the final step is to use LiveCode's XML library to get the required information out of it. If tTree is not an integer then answer error "Failed to process preferences file with error: " & tTree Put revXMLCreateTree(tPreferencesData, false, true, false) into tTree # The revCreateXMLTree function will return a number # (the tree's "handle" or "id") if it succeeds, # otherwise it will return a message saying why it failed. Return empty end if # Create the XML "tree" from the data, # checking to make sure that the file has loaded properly. If tResult is not empty then answer error "Failed to read preferences file at location: " & tPreferencesFile Put url ( "file:" & tPreferencesFile) into tPreferencesData # Always check for the result when reading files # as its possible that the file may have been deleted or moved. Set the itemDelimiter to comma # Read the preferences data from the file into a variable. Put item 1 to -2 of the effective filename of this stack & "/Preferences.xml" into tPreferencesFile set the itemDelimiter to slash local tPreferencesFile # This is not essential but its good practice to avoid tricky bugs # that can arise due to unexpected delimiter values. # Note that we restore the itemDelimiter to comma (its default value) afterwards. # This is for now assumed to be in the same location as the stack / application. private function readPreferencesToXMLTree
#Nested grid start open scriptcase code
This tree allows us to manipulate the XML data easily.Īdd the code to read the XML file as below. This is done in two steps, first the file is read into a variable like any other text file would be, secondly, an XML "tree" is created from the file. Next, we implement a function to read the XML. Note that this code doesn't do anything just yet, because we haven't yet implemented the function readPreferencesToXMLTree and the command processPreferencesTree.
#Nested grid start open scriptcase free
# This will free up the memory that the tree was using and prevent our application # using more memory than it needs or "leaking" memory by creating multiple trees # without closing any of them.

If tTree is empty then exit loadPreferencesĮnd if # Read the preferences we require from the tree and display them. Put readPreferencesToXMLTree() into tTree

The tree is represented as a number, the actual tree structure and data is managed by LiveCode and so we don't need to worry about it. This function reads the XML file, and returns the tree. The second part is to process the tree and extract the data from it. The first part is reading the file into memory and creating an XML "tree". There are two parts to loading the preferences file. When the button is clicked, load up the preferences and put them into the field on mouseUp For this example we are going to load an XML file that contains preferences for our application.īegin the script with the following code:ġ. Edit the script of the button by selecting it, then clicking on the "Script" button in the main menu bar.
