Sure. This first snippet is from the first include file, "XML Parser.dba". It is the load routine. Works like a champ when called from the main dba file.
function XMLLoad(FileNumber, FileName$)
` Clear any contents and open the file.
XMLClearArray(FileNumber)
open to read 1, FileName$
` Get the file size and set a pointer for the file, and one for the array.
iFileSize = file size(FileName$)
pFile = 0
pXML = 1
`----------------------------
` Read it into the XML array.
`----------------------------
repeat
` Skip the first spaces and tabs
char = 0
flag = 1
szTemp$ = ""
while flag = 1
read byte 1, char
inc pFile
if (char <> 32) and (char <> 9) then flag = 0
endwhile
` Store the first character
szTemp$ = szTemp$ + chr$(char)
` Now, get the rest of the line.
flag = 1
while flag = 1
read byte 1, char
inc pFile
` If we reach 0x0D, read the next char (0x0A) and we are done with this line.
if char <> 13
szTemp$ = szTemp$ + chr$(char)
else
read byte 1, char
inc pFile
flag = 0
endif
endwhile
XML$(FileNumber, pXML) = szTemp$
inc pXML
until pFile >= iFileSize
` Store the line count and set the pointer in the XML array to 1
XMLLineCount(FileNumber) = pXML
XMLPtr(FileNumber) = 1
close file 1
endfunction
This second snippet is from the include file "XML Menu.dba". This function is supposed to call the XMLLoad function (shown above), then parse the elements and store values (it's not complete yet...).
function LoadMenu(FileName$)
` Variables we use here.
iLineCount = 0
bResult = 0
bFlag1 = 0
bFlag2 = 0
szElement$ = ""
szValue$ = ""
` Load the menu file.
temp$ = FileName$
XMLLoad(1, temp$)
` Get the line count of this file.
iLineCount = XMLGetLineCount(1)
` Find and store the settings information.
XMLSetPtr(1, 1)
while bFlag2 = 0
` If we've found the <Settings> tag, start storing info.
if bFlag1 = 0
szElement$ = XMLGetElementName$(1)
if szElement$ = "settings"
bFlag1 = 1
endif
XMLMovePtrForward(10)
else
szElement$ = XMLGetElementName$(1)
szValue$ = XMLGetElementValue$(1)
select szElement$
case "backgroundcolor1"
XMLMenuSettings(1).dwBackgroundColor1 = val(szValue$)
endcase
case "backgroundcolor2"
XMLMenuSettings(1).dwBackgroundColor2 = val(szValue$)
endcase
case "backgroundcolor3"
XMLMenuSettings(1).dwBackgroundColor3 = val(szValue$)
endcase
case "backgroundcolor4"
XMLMenuSettings(1).dwBackgroundColor4 = val(szValue$)
endcase
case "font"
XMLMenuSettings(1).szFont$ = szValue$
endcase
case "fontsize"
XMLMenuSettings(1).iFontSize = val(szValue$)
endcase
case "textcolor"
XMLMenuSettings(1).dwTextColor = val(szValue$)
endcase
case "highlightcolor"
XMLMenuSettings(1).dwHighlightColor = val(szValue$)
endcase
case "bordercolor"
if szValue$ = ""
XMLMenuSettings(1).bUseBorder = 0
else
XMLMenuSettings(1).bUseBorder = 1
XMLMenuSettings(1).dwBorderColor = val(szValue$)
endif
endcase
case "startimageid"
XMLMenuSettings(1).iStartImage = val(szValue$)
endcase
case "/settings"
bFlag2 = 1
endcase
endselect
XMLMovePtrForward(1)
endif
endwhile
endfunction
Any ideas?
Good, bad... I'm the guy with the gun. - Ash in Army Of Darkness(1993).
