Hollywood - Extracting data from XML documents

;Here is a small modified extract from an application that I am involved in.  The LoadScript() function will successfully read in data from an XML file using the base: functions provided.
;Feel free to modify and use this in your own Hollywood applications and games.
 
;The base:library I have created contains over 40 useful functions that you can use in Hollywood; an updated version will be available on OS4Depot.  An older version is already available.
 
Function p_scrman:LoadScript(scriptnumber)
    Local data
    Local projectpath = project[0]
    Local xml
 
    scripts[scriptnumber] = {"","","",-999,-999,-999,-999,-999, -999, {}, {} }
 
    If xml <> ""
		If Exists(projectpath  .. "scripts/" .. xml) = True
			OpenFile(1,projectpath .. "scripts/" .. xml)
 
                        ; Skip over the first 7 lines of a typical amiga.com formatted XML file
			For Local skip = 1 To 7
				data = ReadLine(1)
			Next
 
			; Read Script Definitions
			While not Eof(1) and scripts[scriptnumber][8] = -999
 
			  	data = ReadLine(1)
 
				If scripts[scriptnumber][0] = ""
					scripts[scriptnumber][0] = base:GetXMLString(data,"Script Name")
 
				ElseIf scripts[scriptnumber][1] = ""
				    scripts[scriptnumber][1] = base:GetXMLString(data,"Background Bitmap")	
 
				ElseIf scripts[scriptnumber][2] = ""
				    scripts[scriptnumber][2] = base:GetXMLHex(data,"KeyColor")
 
				ElseIf scripts[scriptnumber][3] = -999
				    scripts[scriptnumber][3] = Int(base:GetXMLInteger(data,"Gravity X"))
 
				ElseIf scripts[scriptnumber][4] = -999
				    scripts[scriptnumber][4] = Int(base:GetXMLInteger(data,"Gravity Y"))
 
				ElseIf scripts[scriptnumber][5] = -999
				    scripts[scriptnumber][5] = Int(base:GetXMLInteger(data,"Ground X"))
 
				ElseIf scripts[scriptnumber][6] = -999
				    scripts[scriptnumber][6] = Int(base:GetXMLInteger(data,"Ground Y"))
 
				ElseIf scripts[scriptnumber][7] = -999
				    scripts[scriptnumber][7] = Int(base:GetXMLInteger(data,"Frames"))
 
				ElseIf scripts[scriptnumber][8] = -999
				    scripts[scriptnumber][8] = Int(base:GetXMLInteger(data,"Objects"))
 
				EndIf
 
			Wend
                        CloseFile(1)
		Else
		    base:SystemRequest(locale[61],locale[23],locale[4],#REQICON_WARNING)
		    Return (False)
		EndIf
	Else
		 base:SystemRequest(locale[61],locale[24],locale[4],#REQICON_WARNING)
		Return (False)
	EndIf
EndFunction
 
; You should call this recursively in a While ... data = ReadLine(1)...Wend  structure; ex. call line$ = p_getXmlInteeger(data,"Track ID")
Function base:GetXMLBool(data,key)
    Local result = 0
 
    If FindStr(data,"<key>") > -1
        If FindStr(data,key) > -1
            data = ReadLine(1)
            result = MidStr(data,FindStr(data,"<bool>")+StrLen("<bool>"),StrLen(data))
            result = UnleftStr(result,StrLen("</bool>"))
        EndIf
    EndIf
 
    Return(result)
EndFunction
 
; You should call this recursively in a While ... data = ReadLine(1)...Wend  structure; ex. call line$ = base:GetXMLString(data,"Date Added")
Function base:GetXMLDate(data,key)
    Local result = ""
 
    If FindStr(data,"<key>") > -1
        If FindStr(data,key) > -1
            data = ReadLine(1)
            result = MidStr(data,FindStr(data,"<date>")+StrLen("<date>"),StrLen(data))
            result = UnleftStr(result,StrLen("</date>"))
        EndIf
    EndIf
 
    Return(result)
EndFunction
 
; You should call this recursively in a While ... data = ReadLine(1)...Wend  structure; ex. call line$ = base:GetXMLString(data,"Date Added")
Function base:GetXMLHex(data,key)
    Local result = ""
 
    If FindStr(data,"<key>") > -1
        If FindStr(data,key) > -1
            data = ReadLine(1)
            result = MidStr(data,FindStr(data,"<hex>")+StrLen("<hex>"),StrLen(data))
            result = UnleftStr(result,StrLen("</hex>"))
        EndIf
    EndIf
 
    Return(result)
EndFunction 
 
; You should call this recursively in a While ... data = ReadLine(1)...Wend  structure; ex. call line$ = p_getXmlInteeger(data,"Track ID")
Function base:GetXMLInteger(data,key)
    Local result = 0
 
    If FindStr(data,"<key>") > -1
        If FindStr(data,key) > -1
            data = ReadLine(1)
            result = MidStr(data,FindStr(data,"<integer>")+StrLen("<integer>"),StrLen(data))
            result = UnleftStr(result,StrLen("</integer>"))
        EndIf
    EndIf
    Return(result)
EndFunction
 
; You should call this recursively in a While ... data = ReadLine(1)...Wend  structure; ex. call line$ = base:GetXMLString(data,"Album")
Function base:GetXMLString(data,key)
    Local result = ""
 
    If FindStr(data,"<key>") > -1
        If FindStr(data,key) > -1
            data = ReadLine(1)
            result = MidStr(data,FindStr(data,"<string>")+StrLen("<string>"),StrLen(data))
            result = UnleftStr(result,StrLen("</string>"))
        EndIf
    EndIf
 
    Return(result)
EndFunction